Problem getting user to enter txt file.

Hello,
I am currently writing a program that requires the user to enter the file name for the .txt file. I'm sure I'm just missing something simple. Below is the code.

1
2
3
4
5
6
7
8
9
10
11
12
cout << "Please enter file name: ";

    cin >> textName;
    textName += ".txt";


    // opening txt file.
    fin.open(textName);


    // reads in  data from file
    getline(fin,file);
Unless your compiler supports C++11 where you can pass a string into an fstream constructor you need to pass it as a C style string instead.

fin.open(textName.c_str());
Thank you James, you solved my problem. Have a great night sir.
Topic archived. No new replies allowed.