这是隔离问题的代码:
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
SetConsoleOutputCP(CP_UTF8);
_wsystem(L"echo pure ascii, naïveté");
COORD pos = {0,0};
TCHAR* attempt1 = new TCHAR[14];
DWORD charnum1;
ReadConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), attempt1, 14, pos, &charnum1);
wcout << endl << "charnum1: " << charnum1 << ", attempt1: " << attempt1 << endl;
wcout << "GetLastError: " << GetLastError();
TCHAR* attempt2 = new TCHAR[16];
DWORD charnum2;
ReadConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), attempt2, 16, pos, &charnum2);
wcout << endl << "charnum2: " << charnum2 << ", attempt2: " << attempt2 << endl;
wcout << "GetLastError: " << GetLastError();
system("pause > nul");
}
输出是:
pure ascii, naïveté
charnum1: 14, attempt1: pure ascii, na
GetLastError: 0
charnum2: 0, attempt2: x >
GetLastError: 0
第一次尝试正常,但是当函数尝试使用非 ASCII 字符读取位置时,它什么也不返回,也没有指示任何错误。现在要做什么 ?