我如何不输入名称,而是输入“退出”并关闭程序?
string name;
cout << "Enter a name: "<< " ";
std::getline (std::cin,input);
input[0] = toupper (input[0]);
我如何不输入名称,而是输入“退出”并关闭程序?
string name;
cout << "Enter a name: "<< " ";
std::getline (std::cin,input);
input[0] = toupper (input[0]);
C ++像这样生锈了......
string name;
cout << "Enter a name: "<< " ";
std::getline (std::cin,input);
input[0] = toupper (input[0]);
if (input[0] == 'quit')
{
std::exit;
}
使用 Visual C++
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string strinput;
while (strinput != "quit")
{
cout << "Enter a name: " << endl;
cin.clear();
cin >> strinput;
if(strinput =="quit")
exit(0);
}
return 0;
}