简体   繁体   中英

Convert vector with wchar_t numbers values to wchar_t

I have something like this:

vector<string> elements;

Which contains:

083938F8
083938FA
083938FC
083938FE
08393900
08393902
08393904

And i want to convert those to wchar_t numbers (like a, A, ź, ć);
Can I? And how?

Use std::codecvt standard conversions to translate between two different character encodings:

#include <string>
#include <codecvt>

std::wstring wstring_convert_from_char( const char *str )
{
    std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
    return converter.from_bytes( str );
}

std::string string_convert_from_wchar( const wchar_t *str )
{
    std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
    return converter.to_bytes( str );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM