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()"

Edited 6 Years Ago by Dex02: n/a

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

Edited 2 Years Ago by Dani: Formatting fixed

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();
}
This article has been dead for over six months. Start a new discussion instead.