尝试使用 std::wcout << 时出现错误 C2679 wstring-var; vc++ 2008年快递
当尝试在 vc++ 2008 express 中 wcout a wstring 时,我收到一条相当奇怪的错误消息:
错误 C2679:二进制“<<” :找不到采用“std::wstring”类型右侧操作数的运算符(或者没有可接受的转换)
如果我理解正确,它会报告 wcout 不接受 wstring?我请人在linux下编译这段代码,运行良好。我还在另一台计算机上使用 vc++ 2008 express 尝试了相同的代码,但仍然失败。 vc++ 2008 中 std 的已知问题?
#include <iostream>
int main()
{
std::wstring unicode_test = L"Unicode var";
std::wcout << L"Unicode non-var" << std::endl;
std::wcout << unicode_test << std::endl; //<-- This line fails!
}
我正在使用 vc++ 2008 express sp1 以及 KB948127 之前的所有更新。我知道控制台需要更改代码页,但这甚至没有编译。谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要
#include
。我不确定标准怎么说,但我很确定
不需要导出所有
(如果有)。[edit]至少 cplusplus.com 甚至没有列出
string
作为
中声明的类型。不,这不是标准,我知道......[/编辑]You need to
#include <string>
. I'm not sure what the standard says, but I'm quite sure that<iostream>
is not required to export all of<string>
, if any.[edit]At least cplusplus.com does not even list
string
as the types declared in<iostream>
. No, it's not the standard, I know...[/edit]对于遇到此问题的用户,您可能需要在控制台中启用多字节打印。请参阅此处的答案: https://stackoverflow.com/a/41584090/1599699
我的评论:
For those with this problem, you may need to enable multi-byte printing in the console. See the answer here: https://stackoverflow.com/a/41584090/1599699
And my comment: