It is very simple to add text to the end of my text file in c++. You have to use iostream , fstream and strstream class to do this. I have written follwing program for you which are able to write text at the end of text file. It is very simple program. You have to just put text into buffer and then add this text at the end of file using eof function.
Code:
#include <iostream>
#include <fstream>
#include <strstream>
using namespace std;
int main()
{
char buffer1[2356];
char buffer2[2356];
istrstream ostr1(buffer1, 2356);
istrstream ostr2(buffer2, 2356);
int values1[200];
int values2[200];
int x=0;
ifstream fin("story.txt");
fin.getline(buffer1,2356);
fin.getline(buffer2,2356);
while (ostra1 >> values1[x])
{
ostra2 >> values2[x++];
}
for (int k=0;k<c;x++)
{
cout << values1[k] << ":" << values2[k] << endl;
}
return 0;
}
Bookmarks