+ 1
Adding onto an output file?
Is it possible to use a function prototype to add onto your output file for fstream? Say for example: #include <iostream> #include <fstream> using namespace std; void output(); int main() { ofstream output(“test.txt”); output << “Hello”; output(); return 0; } void output() { output << “world”; } How do I allow it edit the file using function prototypes? Should I refer with ofstream variable? My function has to be like this where it outpus from main and a file. Help please
2 odpowiedzi
+ 2
write prototype of the function like this:
void output(ofstream &output);
and call in main:
output(output);
so it works as you want.
0
The way that works is if you used ofstream outfile (“filename.txt”, ios::app). This will allow u to open the same file in different functions