Hi
I am witing a program to change the the text in a file from "This is an apple" to This is a sample". I need to open the file in append mode too for adding text afterward.
The code for program is:-
#include <fstream>
#include<iostream>
using namespace std;
int main (int argc, char *argv)
{
long pos;
fstream outfile;
outfile.open ("test.txt",ios:out|ios::ate|ios::app);
if (outfile.fail())
{
cout << "Error opening file, errno: " << errno ;
}
pos=outfile.tellp();
cout<<"\n pos is " << pos;
outfile.seekp (pos-7);
cout<<"\n pos is " << outfile.tellp();
outfile.write (" sam",4);
outfile.close();
return 0;
}
The problem is instead of changing the text it adds the word sam in the file. Please help.
Thanks.