Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ file Writing
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
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
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
0 Maciej Los 580
1 OriginalGriff 420
2 Sascha Lefévre 289
3 Abhinav S 220
4 CHill60 200
0 Sergey Alexandrovich Kryukov 9,773
1 OriginalGriff 9,290
2 Peter Leow 5,137
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,036

Advertise | Privacy | Mobile
Web01 | 2.8.150327.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