CFile temp1;
CFile temp2;
temp1.Open(_T("set1.dat"),CFile::modeCreate|CFile::modeReadWrite);
temp2.Open(_T("set2.dat"),CFile::modeCreate|CFile::modeReadWrite);
wchar_t aa[20];
wchar_t bb[20];
temp1.SeekToBegin();
temp2.SeekToBegin();
temp1.Read(aa,temp1.GetLength());
temp2.Read(bb,temp2.GetLength());
AfxMessageBox(aa);aa再次输出乱码,又是unicode的事,从dat文件读出来的字符串存为什么编码?
要怎么处理成unicode.
CFile temp2;
temp1.Open(_T("set1.dat"),CFile::modeCreate|CFile::modeReadWrite);
temp2.Open(_T("set2.dat"),CFile::modeCreate|CFile::modeReadWrite);
wchar_t aa[20];
wchar_t bb[20];
temp1.SeekToBegin();
temp2.SeekToBegin();
temp1.Read(aa,temp1.GetLength());
temp2.Read(bb,temp2.GetLength());
AfxMessageBox(aa);aa再次输出乱码,又是unicode的事,从dat文件读出来的字符串存为什么编码?
要怎么处理成unicode.
存的时候是Unicode,就按照unicode读取,是ANSI的,就按照ANSI读取unicode和ansi转换,就两个函数
WideCharToMultiByte 和 MultiByteToWideChar
应该是doblue aa;
tmp1.Read( &aa, sizeof(double));
看看下面,不要用modeCreate打开已经有的文件。CFile::modeCreate
Directs the constructor to create a new file. If the file exists already, it is truncated to 0 length.
关键是你怎么组织写入/读取的数据内容格式。
你写一个wchar_t, 那同样位置读出来就是wchar_t,
我自始至终都是用unicode编码进行编译的。
另,看看temp1.GetLength的值是多少。
wchar_t aa[20] = {0};
wchar_t bb[20] = {0};
你应该先知道se1.dat是怎么存进去的
当你想把你程序中的某一CString 对象保存进文本文件时,先用WideCharToMultiByte将Unicode模式的转换成ANSI的,然后CFile.Write。