STL解码错误c++

stl codecvt errors c++

本文关键字:c++ 错误 解码 STL      更新时间:2023-10-16

我想使用codecvt将std:wstring转换为std::string,如下所示

#include <ostream>
#include <sstream>
#include <locale>
#include <cstdlib>
#include <codecvt>
//some additional code
typedef std::codecvt_utf8<wchar_t> convert_typeX;
std::wstring_convert<wchar_t> converterX;

我正在使用vs2012,我得到以下编译错误:

error C2825: '_Codecvt': must be a class or namespace when followed by '::'
error C2039: 'state_type' : is not a member of '`global namespace''

所有这些错误都是从

行中的xlocbuf文件生成的
typedef typename _Codecvt::state_type state_type;

_Codevct被定义为模板,有什么问题吗?请帮助!

std::wstring_convert的第一个模板参数应为codecvt类。wchar_t不是这样一个类。你可能想要

std::wstring_convert<convert_typeX> converterX;

如果没有,为什么申报convert_typeX ?