Stream Location Input

Hello. I was just wondering, is there anyway that you can have youre user input the location of a file when trying to using a stream?

Ex of what I want to do:

int main()
{
ifstream instream;
string file_location;

cout << "Enter in file location: " << endl;
cin >> file_location;

instream.open(file_location);



So i want them to input the file location but the program won't compile.
Error messages received while compiling? Also show complete code, and also show it using code tags so it gets properly formatted. Like this:

[code]
1
2
//Code in code tags get formatting
//and line numbering, both being of great help. 
[/code]
1
2
3
4
5
6
7
8
9
int main()
{
  ifstream instream;
  string file_location;

  cout << "Enter in file location: " << endl;
  getline(cin,file_location);

  instream.open(file_location.c_str());
Topic archived. No new replies allowed.