jef*_*pan 2 c++ parameter-passing ifstream
我正在尝试编写一个使用ifstream和scanner来读取文本文件的简单程序.出于某种原因,我收到了这个错误:"In passing argument 1 of 'bool ReadVector(std::ifstream&, Vector<double>&)'".知道我做错了什么吗?
#include <iostream>
#include <fstream>
#include <string>
#include "scanner.h"
#include "genlib.h"
#include "simpio.h"
#include "vector.h"
// prototype
bool ReadVector(ifstream & infile, Vector<double> & vec);
// main
int main(){
Vector<double> vec;
ifstream infile;
infile.open("SquareAndCubeRoots.txt");
if (infile.fail()) Error("Opening file screwed up");
bool foo = ReadVector(&infile, &vec); // stub
cout << foo;
infile.close();
return 0;
}
// stub
bool ReadVector(ifstream & infile, Vector<double> & vec){
return true;
}
Run Code Online (Sandbox Code Playgroud)
ReadVector接受引用,但是你给了一个指针.打电话吧
bool foo = ReadVector(infile, vec);
Run Code Online (Sandbox Code Playgroud)