How to open a file which path or file name contains unicode characters and read or write it's content without using any special API ?. How to do it using only std libraries if it's possible or using only windows API ?. I did try std::wifstream to open a file as in the code sample below, but it doesn't compile. Looks like it doesn't take 'const wchar_t*' argument but 'const char*'. I'm using TDM-GCC 4.7.1 compiler which is included with Dev-C++ IDE.
#ifndef UNICODE
#define UNICODE
#endif
...
#include <clocale>
#include <windows.h>
#include <fstream>
...
int main(int argc, char **argv)
{
setlocale(LC_ALL, "Polish_Poland.852") ;
...
fileCompare(first, second) ;
...
}
...
bool fileCompare(wstring first, wstring second) // This function doesn't compile !
{
using namespace std ;
wifstream fin0(first.c_str(), ios::binary) ;
wifstream fin1(second.c_str(), ios::binary) ;
...
}
Some complete example:
#ifndef UNICODE
#define UNICODE
#endif
#include <clocale>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <string>
#include <iostream>
using namespace std ;
bool fileCompare(wstring first, wstring second) ;
int main(int argc, char **argv)
{
setlocale(LC_ALL, "Polish_Poland.852") ;
wstring first, second ;
first = L"C:\\A.dat" ;
second = L"C:\\E.dat" ;
fileCompare(first, second) ;
getch() ;
return 0 ;
}
bool fileCompare(wstring first, wstring second) // This function doesn't compile !
{
wifstream fin0(first.c_str(), ios::binary) ;
wifstream fin1(second.c_str(), ios::binary) ;
}
Also when I replace L"C:\A.dat" and L"C:\E.dat" to strings containing Polish characters it outputs an error about illegal byte sequence.