|
char pbyReadbuf[100];
CString tmpstr,temp;
if( !myFile.Open(_T("\\myfile.txt"), CFile::modeRead,&e) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
myFile.Read(pbyReadbuf,myFile.GetLength()+1);
//文件内容是“NO.\t\tName\t\tTest_ID\t\tTest_Date\t\tSex\t\tAge\t\tDepartment\t\tRemark\r\n”
pbyReadbuf[myFile.GetLength()] = '\0';
myFile.Close();
int widecharlen=MultiByteToWideChar( //计算从Ansi转换到Unicode后需要的字节数
CP_ACP,
MB_COMPOSITE,
pbyReadbuf, //要转换的Ansi字符串
-1, //自动计算长度
0,
0
);
//tmpstr.GetBuffer(widecharlen); //为转换后保存Unicode字符串分配内存
MultiByteToWideChar( //从Ansi转换到Unicode字符
CP_ACP,
MB_COMPOSITE,
pbyReadbuf,
-1,
tmpstr.GetBuffer(widecharlen), //转换到tmpstr
widecharlen //最多转换widecharlen个Unicode字符
);
int length = tmpstr.GetLength();
为什么length=0?
如果要读取的内容中的"NO."、“Name”等逐一抽取又如何操作呢?请各位指点一下。
|
|