> #include <iostream.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <fstream.h>
use
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
and
using namespace std;
so that there will be compatibility with your code (that is not to
type the std:: prefix)
> int main()
> {
> ifstream infile;
> char file_name[16];
Doesn't your compiler have std::string? std::string is easier to use
than char[].
> printf("\nEnter file name: ");
> cin>>file_name;
>
> infile.open(file_name);
>
> if (infile.fail())
> printf("cant open %s",file_name);
> else
> printf("\nfile %s opened succesfully\n",file_name);
There's the mistake. fail() checks for a fail bit, not if a file open
procedure has failed. So replace the above four lines with (note that
I prefer to use cout than printf; here's a C++ newsgroup):
if (!infile)
cout << "Can't open " << file_name << '\n'; //or (std:

endl
else
cout << "\nFile " << file_name << " opened successfully.\n"; //or
(std:

endl
> infile.close();
> return 0;
> }
If this is all of your code (I doubt it though) then there's no need
to include <iostream> (in your implementation) or in my implementation
there's no need to include <cstdio>. In both implementations there's
no need to include <cstdlib>.
- cmad