标签:
使用的平台:vs2013 控制台
from: http://bbs.csdn.net/topics/360229403
xiayuanzhong:
ofstream ofs( "test.txt", ios::binary | ios::out ); ifstream ifs( "Test_Read.txt", ios::binary | ios::in ); wchar_t temp[ 2 ]; ifs.read( (char *)temp, 2 ); memset( temp, L‘\0‘, sizeof(temp) ); ofs.write( "\xFF\xFE", 2 ); int k = 0; while ( 1 ) { k ++; ifs.read( (char *)temp, 2 ); if ( ifs.eof( ) ) break;//经验表明,放在这里最恰当!~ ofs.write( (char *)temp, 2 ); } ifs.close( ); ofs.close( );
unicode的TXT使用经验:
1.输出 换行符
ofstream ofs_c(FILE_NAME_C, ios::binary | ios::out);
ofs_c.write("\x0D\x00\x0A\x00", 4);// "\r\n"
2.输出空格
WCHAR_NULL8(ofs) (ofs).write("\x20\x00\x20\x00\x20\x00\x20\x00", 8);//" " x 4
用ofstream/ifstream 读写Unicod的TXT
标签:
原文地址:http://www.cnblogs.com/ourran/p/5882739.html