Not sure if that's the (perfect) way to go but the following solution worked for me!
I saved my HTML template file as ANSI (or at least that's what Notepad++ says) and changed every write-to-file-stream-operation:
file << std::string("some text with polish chars: ąśżźćńłóę");
to:
file << ToUtf8("some text with polish chars: ąśżźćńłóę");
where:
std::string ToUtf8(std::string ansiText)
{
int ansiRequiredSize = MultiByteToWideChar(1250, 0, ansiText.c_str(), ansiText.size(), NULL, 0);
wchar_t * wideText = new wchar_t[ansiRequiredSize + 1];
wideText[ansiRequiredSize] = NULL;
MultiByteToWideChar(1250, 0, ansiText.c_str(), ansiText.size(), wideText, ansiRequiredSize);
int utf8RequiredSize = WideCharToMultiByte(65001, 0, wideText, ansiRequiredSize, NULL, 0, NULL, NULL);
char utf8Text[1024];
utf8Text[utf8RequiredSize] = NULL;
WideCharToMultiByte(65001, 0, wideText, ansiRequiredSize, utf8Text, utf8RequiredSize, NULL, NULL);
delete [] wideText;
return utf8Text;
}
The basic idea is to use MultiByteToWideChar()
and WideCharToMultiByte()
functions to convert the string from ANSI (multi byte) to wide char and then from wide char to utf-8 (more here: http://www.chilkatsoft.com/p/p_348.asp). Best part is - I didn't have to change anything else (i.e. std::ofstream
to std::wofstream
or using any 3rd party library or changing the way I actually use the file stream (instead of converting strings to utf-8 which is necessary))!
Probably should work for other languages too, although I did not test that.