First of all, this is normal:
void output(ofstream& out) { out << "does this work?" << endl; }
However, it is not:
int main() { output(ofstream& out); // what is out? ifstream in; in.open("inven.txt"); ofstream out; out.open("results.txt"); return 0; }
This is the first error you get: "Error C2065:" out ": uneclared identifier" because the compiler does not yet know about it.
In the second snippet, you want to output the output using a specific ostream& . Instead of calling a function, you are declaring a function that is not valid in this context. You should call it with the given ostream& :
int main() { ifstream in; in.open("inven.txt"); ofstream out; out.open("results.txt"); output(out);
In this case, you call output with the out parameter.
source share