Solved

ofstream question

Posted on 2002-07-02
4
316 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
ID: 7125182
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
ID: 7125194
std::ios_base::ate sends you to the end of file, is that what you want?
0
 
LVL 30

Expert Comment

by:Axter
ID: 7125312
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
ID: 7125324
Oops!!!
Disregard my previous comment.
I belive jkr is right.  app is what you want.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

828 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