通过重载cout的<<运算符即可实现。
【程序】
【程序】
#include <iostream>
#include <Windows.h>
using namespace std;
// 使C++的cout能输出Unicode字符串
ostream &operator << (ostream &os, const wchar_t *wstr)
{
if (os == cout)
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wstr, wcslen(wstr), NULL, NULL);
return os;
}
int main(void)
{
cout << L"简体中文abc" << endl << L"¿Cómo estás?" << endl;
return 0;
}【运行结果】
本文介绍了一种通过重载C++中的cout运算符来输出Unicode字符串的方法,并提供了一个示例程序,演示了如何使用这种方法输出包含中文和其他Unicode字符的文本。
2417

被折叠的 条评论
为什么被折叠?



