void CAR::count_read()
{
CFile file;
CFileException fe; if (!file.Open(_T("G:\\P\\PRO\\car_count.txt"), CFile::modeRead, &fe))
{
fe.ReportError();
return;
} CArchive ar(&file, CArchive::load);
file.SeekToBegin();
ar >> count; ar.Flush();
ar.Close();
file.Close();


}我在写一个车辆管理系统,可是不知道为什么加入这个函数之后总有这个问题。这个函数就是从一个文件中读取车辆的数目,车辆数目CAR::count是静态变量,这也是被声明为静态函数。这个函数就是想把车的数目都出来。
文件里已经有了一个数字调用函数的位置,在这
void CPRODlg::OnBnClickedButton1()
{
// 登记信息弹框
if (NULL == m_add)
{
m_add = new ADD();
m_add->Create(IDD_ADDITION, this); }
m_add->ShowWindow(SW_SHOW);
//读取车辆数
CAR::count_read();
}

解决方案 »

  1.   

    对CFile文件的操作 用 try catch 捕捉 CFileException
      

  2.   

    我现在改用C语言的方式了
    void CAR::count_read()
    {
    FILE *fp;
    fp = fopen("G:\\P\\PRO\\car_count.txt", "r");
    fscanf(fp, "%d ", &CAR::count);
    }
    }
      

  3.   


    //
    CStdioFile file;
    file.Open("tmp.txt",CFile::modeRead);
    CArchive ar(&file, CArchive::load);
    //
    CString str;
    ar.ReadString(str);
    ar.Flush();
    ar.Close();
    file.Close();
    printf("%s\n", str);
      

  4.   

    // '>>' only for primitive types ! no string