// VS11
#include <codecvt>
#include <string>
#include <locale>
#include <iostream>
#include <fstream>
using namespace std;
typedef codecvt_byname<wchar_t,char,std::mbstate_t> F;
int _tmain(int argc, _TCHAR* argv[])
{
locale::global(locale(locale(),new codecvt_utf8<wchar_t>()));
wstring_convert<F,wchar_t> stows(new F("chs"));
string str="Hello,世界!";
wstring wstr;
wcout.imbue(locale("chs"));
wstr=stows.from_bytes(str);
wcout<<wstr<<endl;
wofstream("E:\\Wout.txt")<<wstr;// 以UTF-8 编码保存
str=stows.to_bytes(wstr);
cout<<str<<endl;
ofstream("E:\\out.txt")<<str;
return 0;
}