I am used to higher level languages (java, python etc.), where this is dead obvious. I am trying to pass a string the user inputs to cin, the name of a file to open. There appears to be some sort of pointer madness error, and my code will not compile. I deleted some of my code to make it more clear.
#include <iostream>
#include <fstream>
using namespace std;
string hash(string filename);
int main(){
cout << "Please input a file name to hash\n";
string filename;
cin >> filename;
cout << hash(filename);
return 0;
}
string hash(string filename){
file.open(filename);
if(file.is_open()){
file.close();
}
...
return returnval;
}
Here is the compile time error.
<code>
$ g++ md5.cpp
md5.cpp: In function ‘std::string hash(std::string)’:
md5.cpp:22: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::open(std::string&)’
/usr/include/c++/4.2.1/fstream:518: note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
</code>
(I know that there are libraries for md5 hashes, but I am trying to learn about how the hash works, and eventually hash collision)