You shouldn't put extended character literals directly into your source code. The value can change depending on how source editor saves the file.
Code:
#include <windows.h>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
std::string wstr_to_str(const std::wstring &wstr, UINT cp = CP_ACP)
{
int len = WideCharToMultiByte(cp, 0, wstr.c_str(), (int)wstr.length(),
0, 0, 0, 0);
if (!len)
return "ErrorA";
std::vector<char> abuff(len + 1);
// NOTE: this does not NULL terminate the string in abuff, but this is ok
// since it was zero-initialized in the vector constructor
if (!WideCharToMultiByte(cp, 0, wstr.c_str(), (int)wstr.length(),
&abuff[0], len, 0, 0))
{
return "ErrorA";
}//if
return &abuff[0];
}//wstr_to_str
using namespace std;
int main()
{
const wchar_t TM = 0x2122;
wstring wide;
wide = L"Skype ";
wide += TM;
wide += L"4.2.2";
string utf8 = wstr_to_str(wide, CP_UTF8);
ofstream f("test.text", ios::out | ios::binary);
if (!f)
{
cerr << "Failed to open file" << endl;
return 1;
}//if
f.write("\xEF\xBB\xBF", 3); // UTF8 BOM
f.write(utf8.c_str(), utf8.length());
f.close();
return 0;
}//main
gg