这是我的代码:
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
using namespace std;
int main() {
cout << "!!!Hello once more" << endl; // prints !!!Hello once more
string word1 = "a";
string word2 = "b";
cout << "enter two words "<< endl;
cin >> word1 >> word2;
while(true) {
cout << word1 << word2 << endl;
cout << "enter two words "<< endl;
cin >> word1 >> word2;
}
}
这应该在用空格隔开的一行中读取两个单词,并将它们存储在我的字符串中,然后再次打印出来。根据http://www.cplusplus.com/doc/tutorial/basic_io/,cin
提取器将空间视为分隔符。
这里是我点击cin
之前调试器及其输出的屏幕截图:
第一张图片是我在阅读用户输入之前的调试器。
下一张图片是我输入jack jill
并按Enter:
为什么调试器将用户输入作为命令处理?我以为控制台是我与程序进行交互的地方?
我测试了程序本身。如果使用.exe
,它可以正常工作。如果我使用Eclipse的调试器,它将无法正常运行,因此这可能是Eclipse调试器的问题。