【奇怪了 Left Right GetLength 都不起作用】

bluestar2009 2012-04-17 05:18:35
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");//设置数据
// }
// }

}


data.txt文件的内容格式如下
1: <1001.3,26.4> <1002.3,26.7> <1003.3,26.7> <1004,26.7> <1005.3,26.7> <1006.3,26.7> <1007.3,26.7> <1008.3,26.7> <1009.3,26.7> <1010.3,26.7>
2: <998.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7>
3: <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7>
4: <998.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7>
5: <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7>
6: <998.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7> <1002.3,26.7>

就是想把这些数据都填充到 List里

结果神奇了 从文件读取的str

Left Right 甚至连GetLength 都不吃

用Find找到\r\n换行符 准备以换行符为位置拆分

结果 不管是Left 还是Right 都拆不开

用GetLength 直接连长度也是0

但是输出的确是文件里全部内容
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluestar2009 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
CString str;

//CFileDialog fileDlg(TRUE);
//if(fileDlg.DoModal() == IDOK)
//{
CFile file;
//file.Open(fileDlg.GetPathName(),CFile::modeReadWrite);
file.Open("data.txt",CFil……
[/Quote]

十分感谢 好了 但是是宽字符的 需要在哪里调成单字符?

我担心一会儿进行转换的时候出错

fenshucangku 2012-04-17
  • 打赏
  • 举报
回复
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();
//}

【str.ReleaseBuffer();】

int len = str.GetLength();

see msdn

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧