why am I getting an error when I pass an ifstream&?
I'm trying to code a simple program that uses an ifstream and scanner to read a text file. For some reason I'm getting this error: "In passing argument 1 of 'bool ReadVector(std::ifstream&, Vector<double>&)'"
. Any idea what I've done wrong?
#include <iostream>
#include <fstream>
#include <string&g开发者_如何转开发t;
#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;
}
ReadVector accepts a reference, but you are giving a pointer. Just call
bool foo = ReadVector(infile, vec);
You're trying to pass a pointer, while the argument is a reference. Remove address-of operators (ReadVector(infile, vec)
).
精彩评论