Compiler tools: Visual C++ 2005 express edition
os platform:
windows xp professional with sp2
Reproduce step:
1.new an "Win32 Console Application"
2.paste the following code in "_tmain" function:
ifstream InFile;
InFile.open(" .txt", ios_base::in);
if (!InFile.is_open())
{
cout << "Can't Not open [" << " .txt" << "] File." << endl;
}
else
{
cout << "Open file [ .txt] success!" << endl;
}
InFile.close();
InFile.open("test.txt", ios_base::in);
if (!InFile.is_open())
{
cout << "Can't Not open [" << "test.txt" << "] File." << endl;
}
else
{
cout << "Open file [test.txt] success!" << endl;
}
InFile.close();
return 0;
3.create two text file named " .txt" and "test.txt" with anything content and put them into test application "Debug" directory,the same path with test application exe.
4.run the test application
the test application will output:
Can't Not open [ .txt] File.
Open file [test.txt] success!

IOStream Bug on Visual Studio 2005 when open Chinese style file name's text file???
Anthony Kautz
Try :
InFile.open(L" .txt", ios_base::in);
Jelle van der Beek30865
BlkShdw88
It is work,thx a lot.
but it is boring when I just programming in ANSI not unicode
Gaturam
you should set the global locale explicitly in VC8 if you want to handle charset other than English using CRT (note: the following code will affect all the CRT code unless you use imbue to set stream's locale seperatedly)
#ifdef _UNICODE
#define _setlocale_acp() //for fstream filename
#define _setstreamlocale_acp() std::locale::global(std::locale(".ACP",std::locale::ctype)) //for fstream to read ansi
#else
#define _setlocale_acp() _tsetlocale(LC_CTYPE,_T(".ACP")) //for fstream filename
#define _setstreamlocale_acp() //for fstream to read ansi
#endif /*_UNICODE*/