I am trying to output a string that I have previously read using cin>>input
until EOF. The problem that I am facing is that after I output the string there is no new line when asking for the next string. I already tried using getline()
, but the problem was that it was not skipping whitespaces. Any clues ?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
while (cin>>input)
{
cout<<input;
}
return 0;
}
Here is an example :
Input:test test
Output: test test
Input:test test... (Previous input remains in stdin)
Sorry in advance if this is a duplicate, but I could not find anything similar.