Click here to Skip to main content
11,929,166 members (51,468 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ file
I have function and i do not know what events are occurred in it. And I used it in many of the main, If i write a file by "ostream" , events are wrote successfully but when the function recalled, the events are cleaned from the text file and it start's to write from the first of the file!!
So, How can i write as appendix in a file ( such as text files ) for continuation?
How do I append to an existing text file?
Posted 18-Jun-12 15:43pm
smss IR402
Edited 18-Jun-12 17:27pm
Wes Aday104.2K
Wes Aday 18-Jun-12 20:49pm
The word you are looking for is "append"
Member 8238193 18-Jun-12 20:53pm
continuation -> append???
Wes Aday 18-Jun-12 20:55pm
Yes. You want to append to your log file or whatever it is. Append means to add onto.
Member 8238193 18-Jun-12 20:58pm
in which sentence?
Wes Aday 18-Jun-12 21:05pm
What do you mean in which sentence? You whole question is about appending to a file not what you call "continuation".
Member 8238193 18-Jun-12 21:51pm
Is a solution with sprinf() function?
Member 8238193 19-Jun-12 17:07pm
Thanks Wes Aday. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Use seekp to set the pointer to the end of the file.

For details read this: ostream::seekp[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I suggest you use fstream instead. It will allow you to specify the mode in which the fie is opened - so you can specify whether to append or truncate an existing file.

See here:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 18 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100