fstream const string 'no matching function'

I have been banging my head on this one for a while. Here's the code:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

const string INFILE = "ihopethisworks.exe";
const string OUTFILE = "ireallyhopethisworks.exe";

void main(){

ifstream inData;
inData.open(INFILE);
/*error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::open(const std::string&)' */

ifstream outData;
outData.open(OUTFILE);
/*error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::open(const std::string&)' */
.
.
.
//this works:
inData.open("ihopethisworks.exe");
outData.open("ireallyhopethisworks.exe");


I can't figure how to use the string constants instead of file names. Help?


doesn't the open function take a const char * as a parameter ?
That's right. You need to use .c_str() to get a C-style string.
Topic archived. No new replies allowed.