How to write UTF-8 widestring to text VC++

find the reason why using wstring instead of string???

ofstream simply wont write wstring, forcing wofstream without codecvt will triger an SEHException (unmanaged code exeption).

wrapp your code with try catch with SEHEException pointer handler

//some fout
}catch ( System::Runtime::InteropServices::SEHException ^ex )

and then

Include this code:

#include <codecvt>

call your function

std::wofstream fout;;
fout.imbue(std::locale(fout.getloc(),new std::codecvt_utf8_utf16<wchar_t>));



it works with vs 2010, dll export to vc# 2013 works very well too 🙂

courtesy to this page


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s