gpt4 book ai didi

c++ - 如何将 wchar_t[] 转换为 basic_string<_Elem>?

转载 作者:行者123 更新时间:2023-11-28 08:07:24 25 4
gpt4 key购买 nike

我需要将项目从 VS2003 转换到 VS2008。在以下代码中:

wchar_t wpom[30];
mbtowc(wpom, "olaboga", 10);

ati_dom::DOMString w = wpom;

我收到一个错误(在最后一行):无法从“wchar_t[30]”转换为“basic_string<_Elem>”。

我尝试将其修改为:

wchar_t wpom[30];
mbtowc(wpom, "olaboga", 10);

std::basic_string<wchar_t> basic_wpom(wpom);
ati_dom::DOMString w = basic_wpom;

但我只完成了另一个错误:无法从 'std::basic_string<_Elem,_Traits,_Ax>' 转换为 'std::basic_string<_Elem>'

如何将 wchar_t[] 转换为 basic_string<_Elem> 而不是 basic_string<_Elem,_Traits,_Ax>...?

最佳答案

只需通过带有指向第一个元素的指针和数组长度的构造函数直接使用 std::wstring:

wchar_t warr[ 30 ];
// populate the array
std::wstring wstrTemp( &warr[ 0 ], 30 );

关于c++ - 如何将 wchar_t[] 转换为 basic_string<_Elem>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10013016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com