C++ 如何进入';退出';关闭程序

C++ 如何进入';退出';关闭程序,c++,string,quit,C++,String,Quit,我需要通过输入“退出”来关闭程序的帮助 比如说 while(true) { cout << "enter a name" << endl; std::getline (std::cin,input); if(input =='quit') { break; } } while(true) { coutquit需要双引号才能成为字符串: #include <iostream> int main() { std::strin

我需要通过输入“退出”来关闭程序的帮助

比如说

while(true)
{
  cout << "enter a name" << endl;
  std::getline (std::cin,input);
  if(input =='quit')
  {
    break;
  }
}
while(true)
{

cout
quit
需要双引号才能成为
字符串

#include <iostream>

int main()
{
    std::string input;
    while (true)
    {
        std::cout << "enter a name: ";
        std::getline(std::cin, input);
        if (input == "quit")
        {
            break;
        }
    }
    std::cout << "Broken" << std::endl;
}
#包括
int main()
{
std::字符串输入;
while(true)
{

std::cout这是什么语言?
无法将字符串与int进行比较
…为什么不能将苹果与桔子进行比较?它们是不同的东西。您可以尝试将字符串转换为int并进行比较,也可以将其转换为int进行比较。但我还需要将输入作为字符串,因为我将在代码中稍后将其与其他变量进行比较…..是你可以不转换为字符串而“退出”程序吗?我删除了我的答案,因为你不断编辑该问题,使其完全更改原始问题。请不要这样做。欢迎使用他的问题的第3版。希望它不会再次更改,从而使你的答案无效:-)@user2855990,因为你已经获得了该问题的答案现在,您应该删除问题的旧版本。也不要忘记接受此答案-单击要接受的答案旁边的复选标记。