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

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?

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.