0
以下代碼旨在連接用戶輸入的單詞。std :: cin的輸入無效
#include <iostream>
#include <string>
int main() {
// insert code here...
std::string s;
std::string concString;
while (std::cin >> s)
{
concString = concString + s;
}
std::cout << concString << std::endl;
return 0;
}
我被卡在這while循環執行期間,因爲我無法打印連接的字符串。我如何退出這個循環?什麼是std :: cin的無效輸入?
在條件語句中使用'break'來擺脫while循環。條件可以是從讀取的最大字數或遇到的特定字中的任何值。 – shark1608 2015-04-01 01:04:34