Hello guys i need some help,
i need a program to read a text file. I write this:

#include <iostream.h>
#include <fstream.h>
#include <cstring.h>
void main () {
int is_open;
  string line;
  ifstream myfile;
  myfile.open ("a.txt");
  if (myfile.is_open())
  {
	 while (! myfile.eof() )
	 {
		getline (myfile,line);
		cout << line << endl;
	 }
	 myfile.close();
  }

  else cout << "Unable to open file";


}

and now i have a error " 'is_open' is not a member of 'ifstream' in function main()"

Recommended Answers

http://www.cplusplus.com/reference/iostream/ifstream/
Maybe it's something to do with your obsolete compiler, with its obsolete headers.

Compilers which accept "#include <iostream.h>" and void main are really not good anymore.

Jump to Post

All 3 Replies

You have to make a file buffer and use file descriptor such as:

 int fd;
 fd=open("d:\\or.txt",O_RDWR | O_CREAT);
 filebuf iofile(fd);

 if(!iofile.is_open())
 {
   cerr<<"The filebuf is not open ";
   return(1);
 }

 iofile.sputn("KaVi International", 21);

As you see when you use is_open it corresponds to file buffer and thus it would show you error of not supported type if you not use it with file buffer. Try this

This is simple.. try this...

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{
 ofstream f1;
 f1.open("Sen.txt",ios::out|ios::trunc);
 if(!f1.fail())
 {
   f1<<"Hello Senthil";
   cout<<"Data written successfully!";
 }
 else
  cout<<"Error";
 getch();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.