0

My Question: I have created a text file named it kashif.txt and i have placed this file in the same folder where .exe and .ccp of this program is placed but file is not opening.
My code is as under.

#include <fstream.h>
#include<iostream.h>

main()
{

char name[100];
char sal[100];
char dept[100]; 
ifstream infile;
char filename[]="kashif.txt";
infile.open(filename);
if (!infile)
{
   cout<<"There is some error in opening the file";
}
   while (!infile.eof())
   {
         infile>>name>>sal>>dept;       
         cout<<name<<"\t"<<sal<<"\t"<<dept<<"\n";
         }

   infile.close();            

}

Program Output: There is some error in opening the file

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by chiwawa10
0

What compiler are you using? fstream.h and iostream.h are big no no's. It should be

#include <iostream>
#include <fstream>

Also I'm not seeing a using namespace std; . Does this actually compile?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.