_setmode() 抛出文档中未提及的异常
我使用 _setmode() 的函数只接受一个字符(例如“K”)并为其打印 unicode 国际象棋国王。输出似乎也很好。唯一的问题是这个例外。我尝试查找 _setmode() 的文档,但找不到原因。
代码(我使用的是 Windows 控制台)
void showPiece(char p)
{
(void)_setmode(_fileno(stdout), _O_U16TEXT);
switch (p)
{
case 'p':
wprintf(L"\x265F");
break;
case 'P':
wprintf(L"\x2659");
break;
case 'r':
wprintf(L"\x265C");
break;
case 'R':
wprintf(L"\x2656");
break;
case 'b':
wprintf(L"\x265D");
break;
case 'B':
wprintf(L"\x2657");
break;
case 'q':
wprintf(L"\x265b");
break;
case 'Q':
wprintf(L"\x2655");
break;
case 'k':
wprintf(L"\x265A");
break;
case 'K':
wprintf(L"\x2654");
break;
case 'h':
wprintf(L"\x265E");
break;
case 'H':
wprintf(L"\x2658");
break;
default:
break;
}
(void)_setmode(_fileno(stdout), _O_BINARY);
}
异常消息:
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!
Program: ...\source\repos\bscs-21099-Chess\x64\Debug\bscs-21099-Chess.exe
File: minkernel\crts\ucrt\src\appcrt\lowio\write.cpp
Line: 626
Expression: buffer_size % 2 == 0
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
The function where I use _setmode(), just takes a character such as 'K' and prints the unicode chess king for it. The output seems to be fine as well. The only problem is this exception. I tried looking up on the documentation of _setmode() but couldn't find the cause.
The code (I am using Windows' console)
void showPiece(char p)
{
(void)_setmode(_fileno(stdout), _O_U16TEXT);
switch (p)
{
case 'p':
wprintf(L"\x265F");
break;
case 'P':
wprintf(L"\x2659");
break;
case 'r':
wprintf(L"\x265C");
break;
case 'R':
wprintf(L"\x2656");
break;
case 'b':
wprintf(L"\x265D");
break;
case 'B':
wprintf(L"\x2657");
break;
case 'q':
wprintf(L"\x265b");
break;
case 'Q':
wprintf(L"\x2655");
break;
case 'k':
wprintf(L"\x265A");
break;
case 'K':
wprintf(L"\x2654");
break;
case 'h':
wprintf(L"\x265E");
break;
case 'H':
wprintf(L"\x2658");
break;
default:
break;
}
(void)_setmode(_fileno(stdout), _O_BINARY);
}
Exception message:
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!
Program: ...\source\repos\bscs-21099-Chess\x64\Debug\bscs-21099-Chess.exe
File: minkernel\crts\ucrt\src\appcrt\lowio\write.cpp
Line: 626
Expression: buffer_size % 2 == 0
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论