i have tried this code, it works fine.
make sure the content of text.txt is "this is an apple" only.
using namespace std;
int main (int argc, char *argv)
cout << "Error opening file, errno: " << endl ;
cout<<"\n pos is " << pos;
cout<<"\n pos is " << outfile.tellp();
outfile.write (" sam",4);