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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.