0
#include <fstream>
#include <string>

using namespace std;
void Readfile(string fname)
{
    ifstream infile(fname);
    if (is_open(infile))
    {
        while (!infile.eof())
        {
            string sline = "";
            getline(infile, sline);
        }
        infile.close();

    }
    else
        stderr << "unable to open file" << fname << endl;

}

Visual studio says identifier "is_open" is undefined even though I included the fstream library.

Risen
  • 61
  • 5
  • It is a member function. – user7860670 Oct 05 '19 at 10:51
  • 1
    Regarding one of your future problems, read [Why is `iostream::eof` inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons) – molbdnilo Oct 05 '19 at 11:03

1 Answers1

2

is_open is a method of the std::ifstream. Use infile object to call it:

ifstream infile(fname);
if (infile.is_open())
{
   //....
}
Nikita
  • 6,270
  • 2
  • 24
  • 37