输出后没有换行符(cin)

问题描述 投票:0回答:1

我正在尝试输出以前使用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中)

抱歉,如果这是重复的,但是我找不到相似的地方。

c++ cin
1个回答
0
投票

如果要在新行上开始控制台输出,则需要附加它,因为cin停在空白处(因此不包括新行)

您需要类似的东西:

cout << std::endl << input;
© www.soinside.com 2019 - 2024. All rights reserved.