首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

CString有关问题,求教

2013-03-29 
CString问题,求教fscanf(fp,%*s %*s %*s)for (int i 0i20i++){CString strName,strHeightint iHei

CString问题,求教
fscanf(fp,"%*s %*s %*s");
for (int i= 0;i<20;i++)
{
CString strName,strHeight;
int iHeight = 0;
fscanf(fp,"%*d  %s %d",strName,&iHeight);
strHeight.Format("%d",iHeight);
GetDlgItem(IDC_EDIT21+i)->SetWindowText(strHeight);
GetDlgItem(IDC_NAME1+i)->SetWindowText(strName);
strName.Empty();

//CHAR NameBuff[20]; CString strHeight =""; int iHeight = 0;
//memset(NameBuff,0,sizeof(CHAR)*20);
//fscanf(fp,"%*d %s %d",NameBuff,&iHeight);
//strHeight.Format("%d",iHeight);
//GetDlgItem(IDC_EDIT21+i)->SetWindowText(strHeight);
//GetDlgItem(IDC_NAME1+i)->SetWindowText(NameBuff);
//UpdateData(FALSE);
}
  fclose( fp );
  MessageBox(_T("导入成功"));
}
求教,各位大侠,我没有注释的代码是有问题的,为什么会崩溃那?我就想把下面的数据从文件里读出。
代码  名称  高度
0  开阔地  6
1  村庄  10
2  低矮建筑  15
3  一般低矮建筑  30
4  一般建筑群  0
5  林地  0
6  水域  50
7  市内高于50米  0
8  灌木林  0
为什么读到第4个(一般低矮建筑 30)就崩溃了,求教大侠是Cstring的问题吗?谢谢 CStirng
[解决办法]
fscanf(fp,"%*s %*s %*s");
for (int i= 0;i<20;i++)
{
CString strName("",20),strHeight("",20);
fscanf(fp,"%*d  %s %s",strName,strHeight);
GetDlgItem(IDC_EDIT21+i)->SetWindowText(strHeight);
GetDlgItem(IDC_NAME1+i)->SetWindowText(strName);
strName.Empty();
}

热点排行