cstring 读取单词出错
BOOL CExampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
·········
CStdioFile file;
file.Open("F:\\c++\\example\\list.txt",CFile::modeReadWrite);
CString str="";
int nCol=0;//列号
int iRow=0;//行号
int nst;//记录查找“,”的位置
int npos;//获取第一个“,”的位置
CString s;//记录单词
while(file.ReadString(str))
{
nst=0;
npos=0;
npos=str.Find(",",nst);
while(npos!=-1)
{
s=str.Mid(nst,npos);
if(nCol==0)
{
m_ListCtrl.InsertItem(iRow,s);
}
else
{
m_ListCtrl.SetItemText(iRow,nCol,s);
}
nst=npos+1;
npos=str.Find(",",nst);
nCol=(++nCol)%4;
if(nCol==0)
iRow++;
}
s=str.Mid(nst);
m_ListCtrl.SetItemText(iRow,nCol,s);
nCol=0;
iRow=0;
}
//关闭文件
file.Close();
m_ListCtrl.Invalidate();
return TRUE;
}
list.txt文件内容如下:
sss,ddd,eee,ggg
sss,ddd,eee,ggg
sss,ddd,eee,ggg
sss,ddd,eee,ggg
sss,ddd,eee,ggg
sss,ddd,eee,ggg
得到的结果却是:(无法给图,列表大概如下)
ddd,eee eee,ggg ggg
sss ddd,eee eee,ggg ggg
sss ddd,eee eee,ggg ggg
sss ddd,eee eee,ggg ggg
请问是哪里出问题?????????
高手指点下········