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?
mark_sAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.