【奇怪了 Left Right GetLength 都不起作用】
void CMy20120417mfcDlg::ReadData() { // TODO: Add your control notification handler code here CString str; //CFileDialog fileDlg(TRUE); //if(fileDlg.DoModal() == IDOK) //{ CFile file; //file.Open(fileDlg.GetPathName(),CFile::modeReadWrite); file.Open("data.txt",CFile::modeReadWrite); file.Read(str.GetBuffer(file.GetLength()),(UINT)file.GetLength()); //GetDlgItem( )->SetWindowText(str); file.Close(); //} int len = str.GetLength(); CString t; t.Format("%d",len); AfxMessageBox(t); char ch[10000] = {0}; char *start,*tail; char tmp[100]={0}; int index=1,j=1; memcpy(ch,str,len); start=tail=ch; CString tmp1; tmp1.Format("%d",index); int nRow = m_List.InsertItem(index, tmp1);//插入行 while (*start!='\0') { if (*start=='<' ) { while ( *tail!='\0') { if (*tail=='>') { start++; strncpy(tmp,start,tail-start); m_List.SetItemText(nRow, j++, tmp);//设置数据 if (j==10) { j=1; index++; tmp1.Format("%d",index); nRow = m_List.InsertItem(index, tmp1);//插入行 } tail++; start = tail; break; } tail++; } } start++; } AfxMessageBox(str); ::MessageBox(NULL,"找到","Warnning",MB_OK); //写入数据// for (index=1;index<=10;index++)// {// CString tmp;// tmp.Format("%d",index);// int nRow = m_List.InsertItem(index, tmp);//插入行// for (int j=1;j<=10;j++)// {// m_List.SetItemText(nRow, j, "text");//设置数据 // } // }}
file.Open("data.txt",CFile::modeReadWrite);
file.Read(str.GetBuffer(file.GetLength()),(UINT)file.GetLength());
//GetDlgItem( )->SetWindowText(str);
file.Close();
//}
【str.ReleaseBuffer();】
int len = str.GetLength();
see msdn