我想为一个更大的程序编写一个小的命令行解释器示例。但是如果我输入"1 2 3“,输出结果是"1\n2\n3\n”,而不是我期望的"1 2 3\n“。
#include <iostream>
int main(int argc, char **argv) {
while (true) {
std::string line;
std::cin >> line;
std::cout << line << std::endl;
}
return 0;
}发布于 2017-07-02 18:08:28
你应该试试getline函数。getline将为您提供预期的输出
#include <iostream>
int main(int argc, char **argv) {
while (true) {
std::string line;
std::getline (std::cin, line);
std::cout << line << std::endl;
}
return 0;
}https://stackoverflow.com/questions/44869592
复制相似问题