Aug 7, 2013 at 6:58am UTC
Can you correct me where i'm going wrong.
Requirement.
1. Need to open existing log file.
2. make note of current end of file(ref1).
3. call_processing_routine (this results in the log file writing ).
4. now read the log file begging at ref1(earlier eof) till the current eof.
Wrote this apparently this is not working.
using namespace std;
#include<iostream>
#include <fstream>
int main () {
string STRING;
fstream infile;
infile.open ("example.txt", ios::in);// | ios::nocreate);// | ios::ate );
if(!infile.is_open()) {
cout<<"error opening\n";
exit (1);
}
infile.seekp(0,ios::end);
getchar(); //During this will open the example.txt and add contents
while(infile.good()) {
getline(infile,STRING);
cout<<STRING<<"\n";
}
infile.close();
}
Last edited on Aug 7, 2013 at 7:01am UTC
Aug 7, 2013 at 8:15am UTC
you need tellp()
to get the current offset (after seekp()
).
After the call of getchar()
you need seekg ()
with the value of the previous tellp()
in order to set the read pointer of the stream