Most of the solutions presented in other threads are unnecessarily converted to obsolete encoding instead of Unicode encoding. Just use reinterpret_cast<const char*>UTF-16 to write files or convert to UTF-8 with WideCharToMultiByte.
, LPTSTR LPWSTR , Windows 9x . LPWSTR " " (, UTF-16), WCHAR wchar_t.
, ( ) UTF-16 UTF-32 ( Linux/OS X):
#include <fstream>
#include <string>
int main() {
std::ofstream stream("test.txt");
std::wstring string = L"Test\n";
stream.write(reinterpret_cast<const char*>(string.data()), string.size() * sizeof(wchar_t));
}