B
ben
Hello,
This really drives me nuts.
Im opening an input file, and Im testing if it was open successfully. Thats
it!
I know that the file that Im trying to open DOES NOT exist but Im getting NO
error message.
No matter what name I enter I get 'file opened successfully"
Any clues? Thanks!
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
int main()
{
ifstream infile;
char file_name[16];
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);
infile.close();
return 0;
}
This really drives me nuts.
Im opening an input file, and Im testing if it was open successfully. Thats
it!
I know that the file that Im trying to open DOES NOT exist but Im getting NO
error message.
No matter what name I enter I get 'file opened successfully"
Any clues? Thanks!
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
int main()
{
ifstream infile;
char file_name[16];
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);
infile.close();
return 0;
}