CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004
    Posts
    118

    Question <codecvt> deprecation - how to compile string/wstring conversion functions without it

    Hi, does anyone know how to rewrite these function to work without the inclusion of the header <codecvt> ? If I include include <locale> without <codecvt> code at bottom of this post doesn't compile with these errors

    main.cpp: In function 'std::string ws2s(const wstring&)':
    main.cpp:230:32: error: 'codecvt_utf8' in namespace 'std' does not name a template type; did you mean 'codecvt_base'?
    230 | using convert_typeX = std::codecvt_utf8<wchar_t>;
    | ^~~~~~~~~~~~
    | codecvt_base
    main.cpp:231:26: error: 'convert_typeX' was not declared in this scope
    231 | std::wstring_convert<convert_typeX, wchar_t> converterX;
    | ^~~~~~~~~~~~~
    main.cpp:231:48: error: template argument 1 is invalid
    231 | std::wstring_convert<convert_typeX, wchar_t> converterX;
    | ^
    main.cpp:233:23: error: request for member 'to_bytes' in 'converterX', which is of non-class type 'int'
    233 | return converterX.to_bytes(wstr);
    | ^~~~~~~~
    main.cpp: In function 'std::wstring s2ws(const string&)':
    main.cpp:238:29: error: 'codecvt_utf8' in namespace 'std' does not name a template type; did you mean 'codecvt_base'?
    238 | using convert_typeX = std::codecvt_utf8<wchar_t>;
    | ^~~~~~~~~~~~
    | codecvt_base
    main.cpp:239:23: error: 'convert_typeX' was not declared in this scope
    239 | std::wstring_convert<convert_typeX, wchar_t> converterX;
    | ^~~~~~~~~~~~~
    main.cpp:239:45: error: template argument 1 is invalid
    239 | std::wstring_convert<convert_typeX, wchar_t> converterX;
    | ^
    main.cpp:242:20: error: request for member 'from_bytes' in 'converterX', which is of non-class type 'int'
    242 | return converterX.from_bytes(str);
    | ^~~~~~~~~~
    mingw32-make: *** [T:\enctest\Makefile.win:28: main.o] Error 1





    Code:
    static std::string ws2s(const std::wstring& wstr)
    {
        using convert_typeX = std::codecvt_utf8<wchar_t>;
        std::wstring_convert<convert_typeX, wchar_t> converterX;
    
        return converterX.to_bytes(wstr);
    }
    
    static std::wstring s2ws(const std::string& str)
    {
    	using convert_typeX = std::codecvt_utf8<wchar_t>;
    	std::wstring_convert<convert_typeX, wchar_t> converterX;	
    
    
    	return converterX.from_bytes(str);
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: <codecvt> deprecation - how to compile string/wstring conversion functions withou

    The example here contains both
    Code:
    #include <locale>
    #include <codecvt>
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured