-
November 2nd, 2011, 05:35 PM
#1
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"
-
November 2nd, 2011, 08:48 PM
#2
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);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|