i have some misunderstanding about tellp, seekg ... functions for example when i run following code
#include <iostream>
#include <ostream>
#include <fstream>
using namespace std;
int main(){
string s("in georgia we are friend to each other");
ofstream out("output.txt");
for (int i=0;i<s.length();i++){
cout<<"file pointer"<<out.tellp();
out.put(s[i]);
cout<<" " <<s[i]<<endl;
}
out.close();
return 0;
}
the result is following
pointer 0
pointer 1 i
pointer2 n
pointer 3
pointer 4 -g
........
and so on . as i understand first pointer 0 it is pointer just file then points to first character in string and so on now consider following code
#include <fstream>
using namespace std;
int main () {
long pos;
ofstream outfile;
outfile.open ("test.txt");
outfile.write ("This is an apple",16);
pos=outfile.tellp();
outfile.seekp (pos-7);
outfile.write (" sam",4);
outfile.close();
return 0;
}
it's result is
This is a sample
this line
pos=outfile.tellp(); i think gets pos to zero as in first example and this fragment what means `outfile.seekp (pos-7)?; pointer to -7 or?
please help thanks`