+ 2
Multiline input in console application
How can I read many lines of input into one string variable in the code playground? (I'm using C++) A message box specifies that we should write multiple inputs in separate lines, so I'm kind of lost. Please help.
3 Answers
+ 2
Just replace the 2nd line with
while( std::getline( std::cin, tmp ) ) result += tmp;
However on (my) pc this doesn't open the input box for some reason.
I usually work around it by placing
#define a(x) std::cin >> x;
on the very last line.
+ 1
You could use a temp variable and a while loop to read from the input stream until there is nothing left and append it to the resulting string.
e.g.
std::string result, tmp;
while( std::cin >> tmp ) result += tmp;
std::cout << result;
Input:
Multiline
input
in
console
application
output:
Multilineinputinconsoleapplication
+ 1
Dennis thanks, it works great! đ