相关疑难解决方法(0)

eof问题c ++

我在Windows XP上使用Dev C++

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main ()
{
    string STRING;
    ifstream infile;
    infile.open ("sample.txt");
        while(!infile.eof)
        {
            getline(infile,STRING); 
            cout<<STRING; 
        }
    infile.close();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

此代码给出以下错误

C:\C++\read.cpp: In function `int main()':

C:\C++\read.cpp:11: error: could not convert `infile.std::basic_ios<_CharT, _Traits>::eof [with _CharT = char, _Traits = std::char_traits<char>]' to `bool'
C:\C++\read.cpp:11: error: in argument to unary !
Run Code Online (Sandbox Code Playgroud)

我不知道这里有什么问题我无法编译代码请帮忙

c++ fstream dev-c++ eof

3
推荐指数
3
解决办法
7739
查看次数

标签 统计

c++ ×1

dev-c++ ×1

eof ×1

fstream ×1