Usage of tellp in C++
<p>I have some misunderstanding about the <code>tellp</code> and <code>seekg</code> functions. For example, when I run the following code.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;ostream&gt;
#include &lt;fstream&gt;
using namespace std;
int main(){
    string s("in Georgia we are friends to each other");
    ofstream out("output.txt");
    for (int i=0; i&lt;s.length(); i++){
        cout&lt;&lt;"file pointer"&lt;&lt;out.tellp();

        out.put(s[i]);
        cout &lt;&lt; " " &lt;&lt; s[i] &lt;&lt; endl;
    }
    out.close();
    return 0;
}
</code></pre>

<p>The result is following.</p>

<pre><code>pointer 0
pointer 1 i
pointer2 n
pointer  3
pointer 4 -g
........
</code></pre>

<p>and so on. As I understand, first pointer 0 it is pointer just file then points to the first character in the string and so on.</p>

<p>Now consider the following code.</p>

<pre><code>#include &lt;fstream&gt;
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;
}
</code></pre>

<p>The result is:</p>

<pre><code>This is a sample
</code></pre>

<p>This line, <code>pos = outfile.tellp();</code>, I think gets pos to zero as in the first example. In this fragment, what does <code>outfile.seekp (pos-7)</code> mean? Pointer to -7 or?</p>
