我正在写一个程序,它必须使用字符,
和
。 我在阅读和打印字符方面遇到了麻烦。 这工作得很好:
#include <iostream>
#include <string>
#include <io.h>
#include <fcntl.h>
using namespace std;
int main()
{
_setmode(_fileno(stdout), _O_U16TEXT);
wstring func = L"x→y";
wcout << func;
}
而这并不:
#include <iostream>
#include <string>
#include <io.h>
#include <fcntl.h>
using namespace std;
int main()
{
_setmode(_fileno(stdout), _O_U16TEXT);
wstring func;
wcin >> func;
wcout << func;
}
不同的输入有不同的问题。 例如,对于输入的xy
,输出是x[?]y
,而如果字符串中包含,那么由于某种原因,我在按回车键后仍然要输入一些东西,然后第一行
之后的所有东西都被丢弃了。 因此对于输入
x→y
stuff
输出为x[?]stuff
。 了解的怪事发生的原因和/或得到一些维护输入和输出的解决方案会很好。 我用的是Windows10。
那么STDIN的编码呢? 在某些情况下,您不能输入特殊符号。