首先,我应该提到我发现了几个密切相关的问题。例如here和 here 。但是,我既不想使用 printf
也不想使用 \n
(因为我已经知道它不起作用)。
用户是否可以在不按回车键的情况下输入换行符(可能是转义序列)?
举个例子:
#include <iostream>
#include <string>
int main () {
std::string a,b;
std::cin >> a;
std::cin >> b;
std::cout << a << "\n" << b;
}
用户是否可以提供单行输入
hello ??? world
这样上面的打印
hello
world
?
最佳答案
你可以这样做
std::string a, b;
std::cin >> a>>b;
std::cout << a << "\n" << b;
用户可以输入空格。
关于c++ - 用户输入的换行符,无需按 Enter 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56338545/