"How can I read an input line (type line) with a space?"
std::string line;
if (std::getline(std::cin, line)) {
...
}
Please note that in addition to checking the return value of the call, std:getlineyou should also avoid biasing the agent >>with the calls std::getline. After you decide to read the file line by line, it seems that it is cleaner and more reasonable to just make one huge loop and perform additional parsing when using a string stream object, for example:
std::string line;
while (std::getline(std::cin, line)) {
if (line.empty()) continue;
std::istringstream is(line);
if (is >> ...) {
...
}
...
}
source
share