尝试使用 std::wcout << 时出现错误 C2679 wstring-var; vc++ 2008年快递

发布于 2024-08-05 14:28:38 字数 639 浏览 11 评论 0 原文

当尝试在 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 之前的所有更新。我知道控制台需要更改代码页,但这甚至没有编译。谢谢。

I'm getting a rather odd error message when attempting to wcout a wstring in vc++ 2008 express:

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring' (or there is no acceptable conversion)

If I understand this correctly it's reporting that wcout does not accept a wstring? I ask someone to compile this code under linux and it runs fine. I also tried the same code on another computer with vc++ 2008 express and still fails. A known issue with std in vc++ 2008?

#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!
}

I'm using vc++ 2008 express sp1 with all the updates up to KB948127. I'm aware that console will need codepage changes but this isn't even compiling. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝不放开 2024-08-12 14:28:38

您需要#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]

迷迭香的记忆 2024-08-12 14:28:38

对于遇到此问题的用户,您可能需要在控制台中启用多字节打印。请参阅此处的答案: https://stackoverflow.com/a/41584090/1599699

我的评论:

由于 sizeof(wchar_t) == sizeof(char) * 2,我在打印实例化的 wstring 时遇到了问题,该 wstring 的长度大于我提供的数据,然后打印之后的任何内容都没有成功。< /p>

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:

I was having trouble printing a wstring that I instantiated with a greater length than the data I was supplying due to sizeof(wchar_t) == sizeof(char) * 2, and then printing anything after that wasn't succeeding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文