Hi, I'm very new to c++ but I'm trying to write a program which displays data from a file.
However, i don't know how to allow the user to specify the file path, only how to specify it myself in code.
ifstream mlb; //create an in file stream
mlb.open("path"); //replace path
i want the user to enter in the file path for this file, any help is greatly appreciated!
i think if not wrong just do this
mlb.open(path.txt);
and the file you creat should bee in the same dirctarey.
Awesome, thank you very much fun2code!
I tried that solution first, but with the path as a string instead of a char.
Thanks!
You're welcome. It will work with a string too if you call c_str() on it:
1 2 3 4
|
string fName;
cout << "Enter filename: ";
cin >> fName;
ifstream mlb( fName.c_str() );
|
Last edited on