problem with eofbit(), failbit() and badbit() functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    int errorCount=0;
    ifstream welcomeFin("Welcome.txt");
    if(!welcomeFin.good())// good() return true if I/O is ok.
    {
        errorCount++;
        ofstream errorPlease ("ErrorDictionary.txt");
        errorPlease<<"Error No: "<<errorCount<<endl;
        if(welcomeFin.eofbit())
            errorPlease<<"0x0001: Ops! EOF has reached.";
        else if(welcomeFin.badbit())
            errorPlease<<"0x0002: Ops! I/O operation has failed.";
        else if(welcomeFin.goodbit())
            errorPlease<<"0x0003: Ops! Logical error occured.";
        errorPlease<<endl;
        errorPlease.close();//closing stream
    }


D:\Projects\Code Blocks\SetFunctions\main.cpp||In function 'int main()':|
D:\Projects\Code Blocks\SetFunctions\main.cpp|38|error: 'std::ios_base::eofbit' cannot be used as a function|
D:\Projects\Code Blocks\SetFunctions\main.cpp|40|error: 'std::ios_base::badbit' cannot be used as a function|
D:\Projects\Code Blocks\SetFunctions\main.cpp|42|error: 'std::ios_base::goodbit' cannot be used as a function|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 1 seconds) ===|
Furthermore, i have already texts files. Welcome.txt and ErrorDictionary.txt in my program directory with .cpp file.
Last edited on
Those are not functions, they are flags (as enumerated in the error messages):
std::ios_base::eofbit
std::ios_base::badbit
std::ios_base::goodbit
std::ios_base::failbit

http://www.cplusplus.com/reference/ios/ios_base/iostate/

What you wanted to use are the member functions, named:
std::ifstream::eof()
std::ifstream::bad()
std::ifstream::good()
std::ifstream::fail()

http://www.cplusplus.com/reference/ios/ios/eof/
http://www.cplusplus.com/reference/ios/ios/bad/
http://www.cplusplus.com/reference/ios/ios/good/
http://www.cplusplus.com/reference/ios/ios/fail/
Last edited on
thanks
Topic archived. No new replies allowed.