I though this would work since ifstream
inherits from istream
string getFileContents(istream& file_contents)
{
string result;
string line;
while (getline(file_contents, line))
result += line + "\n";
return result;
}
then I want to call this function like so:
ifstream file_input;
getFileContents(file_input);
...
getFileContents(cin);
but I get this error in visual studio:
'getFileContents' : cannot convert parameter 1 from std::istream
to std::ifstream &
It should work; are you sure you didn't leave around a wrong prototype that has a parameter of type ifstream &
instead of istream &
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With