Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ file Writing
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 15:43pm
smss IR399
Edited 18-Jun-12 17:27pm
Wes Aday94.3K
v3
Comments
Wes Aday at 18-Jun-12 20:49pm
   
The word you are looking for is "append"
Member 8238193 at 18-Jun-12 20:53pm
   
continuation -> append???
Wes Aday at 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 at 18-Jun-12 20:58pm
   
in which sentence?
Wes Aday at 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 at 18-Jun-12 21:51pm
   
Is a solution with sprinf() function?
Member 8238193 at 19-Jun-12 17:07pm
   
Thanks Wes Aday. :)
Rate this: bad
good
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[^]
  Permalink  
Rate this: bad
good
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: 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
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 18 Jun 2012
Copyright © CodeProject, 1999-2014
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