我想在控制台打印扩展的 ascii 字符,我试过这个:
std::cout << "╔══════════╦════════════════════════════════════════════════════════╗\n";
std::cout << "║ ID:678 ║ Name: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Surname: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Gender: ▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Age: ▓▓▓ ║\n";
std::cout << "║ ║ Tel: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Adress: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ID Print ║ Hobbies: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ░░░░░░ ║ Additional İnformations: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ▒▓▓▓▓▒ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ▓▓▓▓▓▓ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "╚══════════╩════════════════════════════════════════════════════════╝\n";
但是输出是这样的:
?????????????????????????????????????????????????????????????????????
? ID:678 ? Name: ???????????????????????????????????????? ?
? ? Surname: ???????????????????????????????????????? ?
? ? Gender: ?????? ?
? ? Age: ??? ?
? ? Tel: ??????????????????????????????? ?
? ? Adress: ????????????????????????????????????????? ?
? ? ????????????????????????????????????????????????? ?
? ID Print ? Hobbies: ???????????????????????????????????????? ?
? ? ????????????????????????????????????????????????? ?
? ?????? ? Additional ¦nformations: ???????????????????????? ?
? ?????? ? ????????????????????????????????????????????????? ?
? ?????? ? ????????????????????????????????????????????????? ?
?????????????????????????????????????????????????????????????????????
但是当我尝试这个时:std::cout << char(200);
它成功打印'╔'字符。所以我确定控制台支持扩展的 ascii 字符。
所以;我怎样才能正确输出这些 cout?
编辑:使用 std::wcout << L"";
不工作。
Edit2:程序只能在 Windows 7 或更高版本中运行。
编辑3:
使用此代码打印卡片,
#include <fcntl.h>
#include <io.h>
_setmode(_fileno(stdout), _O_U16TEXT);
但是,我无法打印任何正常的 cout 字符,它给出了错误。
(示例错误字符串:std::cout << "Hello!"
)
最佳答案
在windows上写过的小伙伴可以用这个:source( _setmode Windows source )
需要的库:
#include <fcntl.h>
#include <io.h>
将 cout 转换为 Unicode:
_setmode(_fileno(stdout), _O_U16TEXT);
*重要提示:在这种风格中,你总是应该使用 std::wcout << L"";为了这。如果您的代码在其他行中包含 std::cout,则解决方案如下:
当您不需要打印特殊字符时,使用 _setmode(_fileno(stdout), _O_TEXT);
将 stdout 设置回默认文本样式。
关于c++ - 使用 '?' 打印特殊(扩展)ASCII 字符时在输出中获取 `std::cout`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64098108/