Hello... I was wondering if anyone could tell me how to open a file in one function and write data to the file in another? Or is that considered bad programming?
My code is below. It has errors.
Code:#include <iostream> #include <fstream> #include <cstdlib> #include <cstring> void File1(); void File2( ofstream ); int main() { File1(); system("PAUSE"); exit(0); } void File1() { char FILE[65]; strcpy(FILE, "testfile"); strcat(FILE, ".txt"); ofstream fout(FILE, ios::out|ios::app); fout << "File1" << endl; File2(fout); fout.close(); } void File2( ofstream fout ) { fout << "File2" << endl; }



LinkBack URL
About LinkBacks



