Skip to main content
Removed nonstandard and unneeded header.
Source Link
Drew Dormann
  • 65.5k
  • 14
  • 133
  • 200

In the future (VS 2010 already supports it), this will be possible in standard C++ (finally!):

#include <string> #include <locale> #include <codecvt> std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; const std::wstring wide_string = L"This is a string"; const std::string utf8_string = converter.to_bytes(wide_string); 

In the future (VS 2010 already supports it), this will be possible in standard C++ (finally!):

#include <string> #include <locale> #include <codecvt> std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; const std::wstring wide_string = L"This is a string"; const std::string utf8_string = converter.to_bytes(wide_string); 

In the future (VS 2010 already supports it), this will be possible in standard C++ (finally!):

#include <string> #include <locale> std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; const std::wstring wide_string = L"This is a string"; const std::string utf8_string = converter.to_bytes(wide_string); 
`std::wstring` on last line of code sample should be `std::string` - which is the whole point of the question/answer
Source Link
Dan Nissenbaum
  • 14k
  • 22
  • 111
  • 189

In the future (VS 2010 already supports it), this will be possible in standard C++ (finally!):

#include <string> #include <locale> #include <codecvt> std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; const std::wstring wide_string = L"This is a string"; const std::wstringstring utf8_string = converter.to_bytes(wide_string); 

In the future (VS 2010 already supports it), this will be possible in standard C++ (finally!):

#include <string> #include <locale> #include <codecvt> std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; const std::wstring wide_string = L"This is a string"; const std::wstring utf8_string = converter.to_bytes(wide_string); 

In the future (VS 2010 already supports it), this will be possible in standard C++ (finally!):

#include <string> #include <locale> #include <codecvt> std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; const std::wstring wide_string = L"This is a string"; const std::string utf8_string = converter.to_bytes(wide_string); 
Source Link
Philipp
  • 50.1k
  • 12
  • 88
  • 112

In the future (VS 2010 already supports it), this will be possible in standard C++ (finally!):

#include <string> #include <locale> #include <codecvt> std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; const std::wstring wide_string = L"This is a string"; const std::wstring utf8_string = converter.to_bytes(wide_string);