与其这样写代码
while (getline(cin, inputWord))
{
if (inputWord.empty() || inputWord == " " || inputWord == " " || inputWord == " ")return 0;
}
无论存在多少空格,如何让用户终止程序?
最佳答案
制作自己的计算空格的函数:
int countWhiteSpaces(string input)
{
// You do it :) Hint: a 'for' loop might do
}
然后像这样使用它:
while (getline(cin, inputWord))
{
if (inputWord.empty() || countWhiteSpaces(inputWord) > 0)
return 0;
}
关于c++ - 以空格终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21199495/