ofstream::tellp() returns 0 when opening file to append

Hey guys this is my first post here, been reading this site and others for a while and finally ran into a problem that I can't seem to find an answer too.

So I write text to a file, close it, and then open it again, all with ios::app
I want to adjust the put pointer to edit say from the middle or beginning of the file but tellp() always returns 0. This obviously means that seekp(0) does nothing.

Simple example...."outfile.txt" is empty on this run.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
using namespace std;

int main(){

ofstream outfile("outfile.txt", ios::app);
outfile<<"DataHere";
outfile.close();

outfile.open("outfile.txt", ios::app);
cout<<outfile.tellp();
outfile.close();

cin.get();
    return 0;
}

Output is 0.
The answer to this is probably simple but I can't find it.
Thanks.
any ideas out there?
Try using .clear() after you close it.
Topic archived. No new replies allowed.