Hi I'm currently making a studylist program for learning Japanese. I'm using an fstream reader
to read and open my studylists and it works fine when the filename is
in English, however when the filename is in Japanese, or any directory
in the path is Japanese the fstream reader returns a null string.
(actually it returns nothing which I'm assuming is null).
This is strange because reading the studylists (with Japanese entires) is fine, yet if the file is in Japanese it fails.
Am I missing something Thanks

fstream with Japanese filenames?
Tao Ma
Also I just realised I wasn't entirely clear on the problem. It actually isn't a problem with the fstream. I'm using an openFileDialog instance to get the name of the file and the process goes something like this.
/* convert the String^ to a char* for fstream taken from MSDN forums */
// set the name as the CURRENTFILENAME
pin_ptr<const wchar_t> wch = PtrToStringChars(openFileDialog1->FileName->ToString());
// conver to a char*
size_t origsize = wcslen(wch)+1;
const size_t newsize = 100;
size_t convertedChars = 0;
char nstring[newsize];
wcstombs_s(&convertedChars, nstring, origsize, wch, _TRUNCATE);
currentFileName = nstring;
fstream reader;
reader.open(currentFileName, ios::in);
I've realised going using breakpoints that the convert to char* function is what returns the null value. It doesn't process the Japanese characters.
Davide Levorato
tyrone
MichelLef
Also it's a lot easier to convert a System String to wchar_t
Arun Goel
Frank Potter seems to have had the same problem as you. You might useful information in his post over at http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=371229&SiteID=1.
To check if the file could not be opened, you're supposed to check the fail bit of the ifstream.
ifstream ifFile(...);
if(ifFile.fail())
{
/* Could not open file */
}
steve1980
Did the setlocale functions not work
Alternatively, you can skip converting the string to char* and just pass the wchar_t*.
/* convert the String^ to a char* for fstream taken from MSDN forums */
// set the name as the CURRENTFILENAME
pin_ptr<const wchar_t> wch = PtrToStringChars(openFileDialog1->FileName->ToString());
fstream reader;
reader.open(wch, ios::in);
The ability to pass wchar_t* filenames to fstream::open is a new feature for VS2005.