fstream and string

Hey guys,

I've used C++.com's reference quite a few times and I usually don't ask questions unless I've come to a dead end. So here is what I've got going on. I've got this monolithic code that reads in some information from an external data file. I've got this segment in the file:

1
2
3
4
5
6
7
8
9
10
    cout<<"Hi there, what file contains the data? "<<endl; 
    cin>>fileIn;
    system("cls");
    cout<<"What's the name of the output file?"<<endl; 
    cin>>fileOut; 

   //Declaring the files that need to be destroyed....I meant opened. :D 
    fstream inData(fileIn); //File to be read
    ofstream outData(fileOut); //File to write
   


fileIn and fileOut are both strings. I'm getting an error message about the previous segment...obviously.

So here's my thing, I'm just wondering if I'm missing a library to include or if fstream can't handle a string input. This isn't for a class. Any help is welcomed.

Thanks in advance.
For the file name, fstreams take in a const char* as a parameter in the constructor.

Try this instead:

1
2
fstream inData(fileIn.c_str()); //File to be read
ofstream outData(fileOut.c_str()); //File to write 
Topic archived. No new replies allowed.