我正在尝试构建一个命令行应用程序,我刚开始,我正在尝试获取一个 wchar_t 输入并打印它,但是如果我输入“foo foof”,它会打印 foo>>> foo>>>>
。
这是我的代码:
#include <iostream>
using namespace std;
int main()
{
while (1 == 1)
{
wchar_t afterprint[100];
wcout << "\n>>> ";
wcin >> afterprint;
wcout << afterprint;
}
return 0;
}
这是控制台中发生的事情:
>>> foo foof fofof
foo
>>> foof
>>> fofof
>>>
我期望发生的事情是,它在一个 行上打印输入的内容。
非常感谢您的帮助,如果答案真的很明显,我很抱歉,因为我是 C++ 的新手。
最佳答案
我看到这个问题从一次获取 1 个字符的问题演变为一次获取 1 个单词的问题。您可以使用 fgetws
来捕获整个输入:
while (1)
{
wchar_t afterprint[100];
std::wcout << "\n>>> ";
fgetws(afterprint, 100, stdin);
std::wcout << afterprint;
}
关于c++ - 如何一次打印带有空格的整个 wchar_t? (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47025380/