HW_6c - Append data to existing data in a file.
the results.txt file.
end of the existing data).
/* OUTPUT
Here are the numbers in the file:
3
4
5
Enter 3 more numbers:
6
7
8
The numbers have been written (appended) to results.txt.
Press any key to continue . . . */
Please make the code based on C++, and make a description for each code.
Here is the solution. Please do upvote thank you.
#include<iostream>
#include<fstream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int num,i;
ofstream fout;
cout<<"Add 3 more numbers"<<endl;
fout.open("sample.txt",ios::app);
assert(!fout.fail());
for(i=0;i<3;i++)
{
cin>>num;
fout<<num<<endl;
}
fout.close();
assert(!fout.fail());
return 0;
}
Before writing:
After adding 3 numbers:
Get Answers For Free
Most questions answered within 1 hours.