我需要通过输入“退出”来关闭程序的帮助
例如。
while(true)
{
cout << "enter a name" << endl;
std::getline (std::cin,input);
if(input =='quit')
{
break;
}
}
它没有爆发或退出,你为什么不能将字符串与 int 进行比较?
即:while (input != 'quit') <<-- 那也行不通。
quit
需要用双引号括起来才能成为string
:
#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;
}
看它运行。
还有你怎么不能比较 a
string
和 aint
。
因为这种行为不是由c++标准定义的。将"1.0"
等于?1