我无法使用 fstream 读取.dat文件

I can't read a .dat file using fstream

本文关键字:读取 dat 文件 fstream      更新时间:2023-10-16

我知道这个主题有很多问题,但我无法解决。这个程序在我的笔记本电脑上运行得很好,但当我试图在学校的Linux实验室中编译和运行它时,这个程序无法打开文件。我曾尝试定义文件的绝对位置,但没有任何效果。文件名是正确的,但当我尝试运行程序时,它显示"失败"。我正在使用gedit并使用bash编译程序。

    ifstream fin("rainfall.dat");       // If the file cannot open display failed
    if(fin.fail()){
    cout << "failed" << endl;
    return 1;
    }

尝试

#include <errno.h>
    if(fin.fail())
        perror("open failed ");

这将为最后一个错误

提供一条可读的消息