lundi 18 juin 2018

Passing a string argument to ifstream

I'm trying to pass a string argument to a function from the main function and then passing this received string argument to ifstream constructor. I'm able to receive this string in the function, but when I pass this argument to ifstream, I get a error message:

no matching function for call to ‘std::basic_ifstream::basic_ifstream(const string&)’ std::ifstream file(fileName);

Here is my code:

int** read_CSV(std::string const& fileName)
{

 //cout<<fileName<<"\n";//this works

 std::ifstream file(fileName);//problem

 //Rest of logic
}

The main function:

int main()
{

 int** inputMatrix1 = read_CSV("inputData4_80-20_100x32.csv");

 return 0;
}

The variable fileName is creating the problem. If I pass it as it is, it gives the error. But instead, if I explicitly mention the name of the file using string rather than the variable, the code works fine. Can someone explain what exactly is the problem here and how I can solve it?

Aucun commentaire:

Enregistrer un commentaire