我正在尝试输出以前使用cin>>input
读取的字符串,直到EOF。我面临的问题是,在输出字符串后,在请求下一个字符串时没有新行。我已经尝试过使用getline()
,但是问题是它是不跳过空格。有任何线索吗?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
while (cin>>input)
{
cout<<input;
}
return 0;
}
这里是一个例子:
输入:测试测试
输出:测试测试
Input:test test ...(先前的输入保留在stdin中)
抱歉,如果这是重复的,但是我找不到相似的地方。
如果要在新行上开始控制台输出,则需要附加它,因为cin
停在空白处(因此不包括新行)
您需要类似的东西:
cout << std::endl << input;