-
ofstream help
i have 3 files
main.cpp
functions.cpp
header.h
the main.cpp contains only the open and close ofstream functions for the text file.
the functions.cpp output ofstream line to the text file
header.h just contains what they always contain.
where do i put ofstream outf; (for example) and include<fstream>
so that the main and function cpps can identify the "outf << " or "outf"
-
Re: ofstream help
pass the ostream object created in main to the functions by reference.
Code:
void foo(ostream & out)
{
out << "whatever\n";
}
int main()
{
ofstream outfile("out.txt");
foo(outfile);
}