. , MultiByteToWideChar() , multiByteStr, , . , . MultiByteToWideChar(), , , . . , .
:
#define UNICODE
#include <Windows.h>
#include <cstdio>
#include <fstream>
using namespace std;
void pause()
{
wcin.ignore();
wcin.get();
}
int main()
{
FILE* resFile;
char multiByteStr[256] = {0};
ifstream oFile;
FILE* exampleFile;
WCHAR buffer[256] = {0};
SetConsoleOutputCP(CP_UTF8);
resFile = _wfopen(L"foo",L"w, ccs=UTF-8");
if (!resFile) {
wprintf(L"Unable to create foo");
goto done;
}
fwprintf(resFile,L"%s",L"C:\\exsistingFolder\\zażółć gęśłą jaźń ☺☻♥♦• ć.txt");
fclose(resFile);
if (!oFile.open(L"foo")) {
wprintf(L"Unable to open foo");
goto done;
}
oFile.getline(multiByteStr,255,'\n');
oFile.close();
if (MultiByteToWideChar(CP_UTF8,0,multiByteStr,-1,buffer,256) == 0) {
wprintf(L"Unable to convert UTF-8 to UTF-16. Error: %u", GetLastError());
goto done;
}
exampleFile = _wfopen(buffer,L"w, ccs=UTF-16LE");
if (!exampleFile) {
wprintf(L"Unable to create file: %s", buffer);
goto done;
}
fwprintf(exampleFile,L"%s",buffer);
fclose(exampleFile);
wprintf(L"created file: %s", buffer);
done:
pause();
return 0;
}