Click here to Skip to main content
Sign Up to vote bad
good
See more: C++fileWriting
Hi.
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 - 14:43
Edited 18 Jun '12 - 16:27
Wes Aday59.2K

Comments
Wes Aday - 18 Jun '12 - 20:49
The word you are looking for is "append"
Member 8238193 - 18 Jun '12 - 20:53
continuation -> append???
Wes Aday - 18 Jun '12 - 20:55
Yes. You want to append to your log file or whatever it is. Append means to add onto.
Member 8238193 - 18 Jun '12 - 20:58
in which sentence?
Wes Aday - 18 Jun '12 - 21:05
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:51
Is a solution with sprinf() function?
Member 8238193 - 19 Jun '12 - 17:07
Thanks Wes Aday. :)

2 solutions

Use seekp to set the pointer to the end of the file.
 
For details read this: ostream::seekp[^]
  Permalink  
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: http://www.cplusplus.com/reference/iostream/fstream/open/[^]
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,386
1 OriginalGriff 6,596
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


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