I know how to open a file if the name is coded into the source code, but how so I use a user-entered file and path with
ifstream datafile;
datafile.open("x:\\file.dat");
where x:\\file.dat is entered by the user of the program at runtime
thanks
I know how to open a file if the name is coded into the source code, but how so I use a user-entered file and path with
ifstream datafile;
datafile.open("x:\\file.dat");
where x:\\file.dat is entered by the user of the program at runtime
thanks
ifstream takes a char * as the first argument for the open method. Have the user enter the filename into a char array and use that as the argument.
-PreludeCode:char array[BUFSIZ]; cin.getline ( array, BUFSIZ ); datafile.open ( array );
My best code is written with the delete key.
using a char array as the argument for ifstream is not working for me. the program never opens the file and it just hangs. is there a special way to format the text that I input while the program is running? I am entering the file name as I would in the source, but omitting the quotes ("). It works if I hard code the file name into the source.
Here's a small program...
-----
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<dir.h>
void main()
{
char path[13],name[13]
ofstream fout;
cout<<"Enter path : ";
gets(path);
cout<<"Enter filename : ";
gets(name);
chdir(path);
fout.open(name);
fout<<"FILE HAS BEEN EDITED";
fout.close();
}
-----
hope this helps
-