-1

我如何不输入名称,而是输入“退出”并关闭程序?

string name;

cout << "Enter a name: "<< " "; 
std::getline (std::cin,input);
input[0] = toupper (input[0]);
4

1 回答 1

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;   
}
于 2013-10-07T19:27:11.620 回答