Opening a file with name in UNICODE format
-
Hi, I am trying to open a file, whose name is in UNICODE string with a Byte-order Mark (BOM). How do I open such files? The CFile class fails to recognize such a name. Thank you. AJ
#include <fstream>
wchar_t file_name[] = L"hello.txt"; // ... Your file name source.
// std::fstream f(file_name, std::ios::in | std::ios::out);
std::wfstream f(file_name, std::ios::in | std::ios::out);
Maxwell Chen
modified on Thursday, December 27, 2007 4:01:06 AM
-
#include <fstream>
wchar_t file_name[] = L"hello.txt"; // ... Your file name source.
// std::fstream f(file_name, std::ios::in | std::ios::out);
std::wfstream f(file_name, std::ios::in | std::ios::out);
Maxwell Chen
modified on Thursday, December 27, 2007 4:01:06 AM
-
Thank you for your reply. But an existing file with Byte-order Mark (Ex: FFFE), will not open with the above code.
Ajay L D wrote:
But an existing file with Byte-order Mark (Ex: FFFE), will not open with the above code.
I just made a file with the mark
EF BB BF
in the beginning three bytes of the content, and the content is in Chinese. I use the below code, and it can open and load data into fstream variable. (Sorry for my typo in last reply. Note the "w" of the type name.)std::wifstream file(file_name, std::ios::in | std::ios::binary);
12-27 05:12 pm> The content loaded is incorrect... :sigh: 12-27 06:10 pm> Oh you have to use
binary
mode to open Unicode files. Reference: www.gamedev.net/community/forums/topic.asp?topic_id=362755
Maxwell Chen
modified on Thursday, December 27, 2007 5:11:48 AM