#ifndef UNICODE
#define UNICODE
#endif
#include <Windows.h>
#include <cstdio>
#include <fstream>
using namespace std;
int main()
{
FILE* resFile;
char multiByteStr[256];
ifstream oFile;
FILE* exampleFile;
TCHAR buffer[256];
system("chcp 65001");
resFile = _wfopen(L"foo",L"w, ccs=UTF-8");
fwprintf(resFile,L"%s",L"C:\\exsistingFolder\\zażółć gęśłą jaźń ☺☻♥♦• ć.txt");
fclose(resFile);
oFile.open(L"foo");
oFile.getline(multiByteStr,256,'\n');
oFile.close();
MultiByteToWideChar(CP_UTF8,0,multiByteStr,256,buffer,256);
wprintf(L"%s",buffer);
exampleFile = _wfopen(buffer,L"w, ccs=UTF-16LE");
fwprintf(exampleFile,L"%s",buffer);
fclose(exampleFile);
system("pause");
return 0;
}
As you can see, program should create file "foo" resFile
that contains a full path of the file to be created, and this new file exampleFile
should contain a path to itself. Although during debugging in Visual studio 2010 autos yields that buffer has the correct string, exampleFile isn't created. Why?
And another thing: why wprintf
doesn't output extended characters, though I've switched console's font to Lucida Console - that one which can deal with uncode characters.
Ps. exampleFile points to NULL
, even after _wfopen
, and the last character of buffer is '/0'
.