VS中MFC读取txt数据

        CFileDialog open_dlg(true,NULL , NULL , OFN_FILEMUSTEXIST | OFN_READONLY | OFN_PATHMUSTEXIST , TEXT("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|") , NULL);

if(open_dlg.DoModal() == IDOK)
{
filename = open_dlg.GetPathName();
UpdateData(FALSE);
}
AfxMessageBox(filename);


CStdioFile   fileReader;
CFileException error;


if (!fileReader.Open(filename, CFile::modeRead, &error))
{
TCHAR szError[1024];
error.GetErrorMessage(szError, 1024);
CString strErr;
strErr.Format(_T("创建匹配列表文件 match_list.txt 失败!"));
AfxMessageBox(strErr);
return;

}

        double **s;

s=(double **)malloc(100*sizeof(double *));    //s为存放txt文件数据数组
for(int i=0;i<15;i++)  
s[i]=(double *)malloc(sizeof(*s)); 

int i=0;

CString strLine,strtemp;
while(fileReader.ReadString(strLine))

/*USES_CONVERSION;*/
char *str = strLine.GetBufferSetLength(strLine.GetLength());
char *p;
int j=0;
if(strLine!="")

for (p=strtok(str,"  ");p!=NULL;p=strtok(NULL,"  "))
{
strtemp = p;
s[i][j]=atof(strtemp);

j++;


MessageBox(strtemp);
}

}
i++;
}

你可能感兴趣的:(VS中MFC读取txt数据)