大家进来看看
需要循环读取文件,并得到每个文件的第二行内容 以下是计算按钮的消息响应函数,其中m_mshow为与输出编辑框关联的变量,i_itime为时间输入编辑框关联的变量,赋初值为20.
用C++函数测试也读不出来,文件名能得到,就是读不出其中的内容(可读的)。大家帮看看
void CMaDlg::OnCalculator()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int static iFileNum=0; //文件数
int static iTimeDiff=0; //时间差
CString cGetFileName; //保存文件名
CString cGetFileLine; //保存文件第二行
CString cOutFileNum; //保存输出文件总数
CString cTimeDiff; // 保存输出时的时间差值
char ch[100]; //C++函数测试用的定义的一个数组
memset(ch,0,100);
CFileFind GoFindFile;
CStdioFile CSFile;
BOOL next;
next=GoFindFile.FindFile("all\\*.txt"); //第一次遍历,得到文件总数
while (next)
{
next=GoFindFile.FindNextFile();
iFileNum++;
}
m_sshow.Empty();
m_sshow+=L"共有文件:";
cOutFileNum.Format("%d",iFileNum);
m_sshow+=cOutFileNum;
m_sshow+="\r\n";
GoFindFile.Close();
next=GoFindFile.FindFile("all\\*.txt"); //得到每个文件的文件名,然后取出第二行并比较这两个时间,判断输出
while (next)
{
next=GoFindFile.FindNextFile();
cGetFileName=GoFindFile.GetFileName();
m_sshow+=cGetFileName;
GoFindFile.Close();
// ifstream itf(cGetFileName); //C++文件操作实验代码,得到文件第二行
// itf.read(ch,100);
// itf.close();
// cGetFileLine.Format("%s",ch);
// cGetFileLine=cGetFileLine.Mid(1+cGetFileLine.Find("\n"),23);
CSFile.Open(cGetFileName,CFile::modeRead); //CStioFile 类函数读取第二行
CSFile.ReadString(cGetFileLine);
CSFile.ReadString(cGetFileLine);
CSFile.Close();
m_sshow+="\t";
m_sshow+=cGetFileLine;
m_sshow+="\t";
m_sshow+=L"文件时间-GPA=";
// iTimeDiff=Time(cGetFileLine)-Time(cGetFileName); // 计算时间差值
cTimeDiff.Format("%d",iTimeDiff);
m_sshow+=L"时间差:";
m_sshow+=cTimeDiff;
if (m_itime>=fabs(iTimeDiff))
m_sshow+=L" right";
else
m_sshow+=L" wrong";
m_sshow+="\r\n";
}
UpdateData(FALSE);
}