Solved

ofstream question

Posted on 2002-07-02
4
314 Views
Last Modified: 2010-04-01
I want to open a file and seek to the end of it, but whenever the file is opened using the following code, it is truncated...

std::ofstream queue;

queue.open("file.000", std::ios_base::out | std::ios_base::ate);

any suggestions?
0
Comment
Question by:mark_s
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
Comment Utility
Try

queue.open("file.000", std::ios_base::out | std::ios_base::app);

istead to open it in 'append' mode - from what you wrote, it seems to be what you actually want to do...
0
 

Expert Comment

by:nke2000
Comment Utility
std::ios_base::ate sends you to the end of file, is that what you want?
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
Try using std::ios_base::trunc instead.
Example:
queue.open("file.000", std::ios_base::out | std::ios_base::trunc);
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
Oops!!!
Disregard my previous comment.
I belive jkr is right.  app is what you want.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now