How to make user input multiline string data in c++?
I tried getline(cin, .... ), but this cannot take input more than one line. The en开发者_Go百科d of input is determined by something like #.
You can use getline with a different character than '\n' as the delimeter.
// will collect input until the user enters a #
getline(cin,mystring,'#');
Try something like:
#include <iostream>
...
std::string input;
while(1)
{
input = "";
std::cin >> input;
if(input[input.size() - 1] == '#')
break;
}
Use C++ stuff, not C stuff.
Can't you just concatenate the strings for each line?
I'd go for conio.h
(or whatever else your platform has if it doesn't have conio) and just write an input method myself. That way you can make it much prettier and foolproof.
精彩评论