方法1:使用win32 api函数
PCTSTR str1 = TEXT("123456789");
AllocConsole();
HANDLE HConsole = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(HConsole, str1, 9, NULL, NULL);
https://learn.microsoft.com/zh-cn/windows/console/writeconsole
方法2:重定向输入输出
AllocConsole();
FILE* stream;
_tfreopen_s(&stream,TEXT("CONOUT$"), TEXT("w"), stdout);//tchar.h
cout << "This is a test info" << endl;
https://learn.microsoft.com/zh-cn/cpp/c-runtime-library/reference/freopen-s-wfreopen-s?view=msvc-170
https://www.cnblogs.com/MuSmile/p/5245744.html