对于我的任务,我正在构建一个堆,堆的数据来自一个文件。其中一个功能是获取数据,但我无法理解 ifstream read() 函数,因此我遇到了一个非常讨厌的错误,这就是我所拥有的:
template<class T, class P>
void get_list(vector<T>& v, const char* file_loc, P func) {
T data;
ifstream inFile;
inFile.open("file_loc");
if (!inFile) {
cerr << "Error - unable to open input file\n";
exit(1);
}
inFile.read( &data, sizeof(T));
while (inFile) {
inFile.read( &data, sizeof(T));
insert(v,data,func);
}
inFile.close();
}
我收到的错误是:
prog7.h:53: error: no matching function for call to
‘std::basic_ifstream<char, std::char_traits<char> >::read(int*, long unsigned int)’
/usr/include/c++/4.3/istream:468: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,_Traits>::read(_CharT*, std::streamsize)
[with _CharT = char, _Traits = std::char_traits<char>]
任何帮助将非常感激!