Please Help! Can't write to the end of the file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Please Help
How to write to the end of the file

#include <fstream
using namespace std

out.open("aaa.rep");
int i = out.tellp();
out.seekp( 0, ios::end )
out<<lpTime.wDay<<"/"<<lpTime.wMonth<<"/"<<lpTime.wYear<<" "<<lpTime.wHou
out.close()

thank you
Pol
 
Hi Pola,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to use the ofstream to
append the data from the end of the file.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think you may try the code below.

#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
SYSTEMTIME lpTime;
GetSystemTime(&lpTime);
ofstream x;
x.open( "aaa.rep",ios_base::app); // file contains line: 012345678
x<<lpTime.wDay<<"/"<<lpTime.wMonth<<"/"<<lpTime.wYear<<" "<<lpTime.wHour;
x.close();
return 0;
}

As for the seekp function, from the MSDN:
Reset position in output stream.
It is used to reset the posistion in output stream, when you open file as
ofstream, the original file content is not the ofstream. So it seems the
seekp did not work, and I think it works as the design.

basic_ostream::seekp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/ht
ml/vclrf_ostream_basicostreamseekp.asp

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Pola,

Thanks for posting in the community.

If you have any concern on this issue, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top