c++visual-studio-2012c++11stlcodecvt

stl codecvt errors c++


i want to use the codecvt to convert the std:wstring to std::string like so

#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;

I'am using vs2012, and i get the following compilation errors:

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

All this errors generates from the file xlocbuf on the line

typedef typename _Codecvt::state_type state_type;

_Codevct is defined there as template, what can be wrong with it? Please help!


Solution

  • The first template parameter of std::wstring_convert should be a codecvt class. wchar_t is not such a class. You likely want

    std::wstring_convert<convert_typeX> converterX;
    

    If not, what have you declared convert_typeX for?