[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

ofstream question

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
mark_s
Asked:
mark_s
  • 2
1 Solution
 
jkrCommented:
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
 
nke2000Commented:
std::ios_base::ate sends you to the end of file, is that what you want?
0
 
AxterCommented:
Try using std::ios_base::trunc instead.
Example:
queue.open("file.000", std::ios_base::out | std::ios_base::trunc);
0
 
AxterCommented:
Oops!!!
Disregard my previous comment.
I belive jkr is right.  app is what you want.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now