如何进入'退出'关闭程序?

时间:2013-10-07 19:20:13

标签: quit

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

string name;

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

1 个答案:

答案 0 :(得分: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;   
}