Solved

Append mode?

Posted on 2001-06-19
3
498 Views
Last Modified: 2013-11-20
This might sound like an easy question but anyway:) How do we open a file in append mode in MFC??
0
Comment
Question by:mejaz01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6208083
Hi!
you can use _open file with  _O_APPEND flag
and then use CFile constructor with getted file handle
i.e.
int flH = _open( "OPEN.OUT", _O_WRONLY | O_APPEND|_O_BINARY|_O_CREAT, _S_IREAD | _S_IWRITE );

CFile file(flH);
note that this file will not be closed in the file destructor so
use:
 _close((HFILE)file);
;
0
 
LVL 2

Accepted Solution

by:
TravisHall earned 50 total points
ID: 6208600
Use CFile::modeNoTruncate (combined with CFile::modeCreate). To append to the end of the file, I think you will have to follow up your CFile::Open() with CFile::SeekToEnd().
0
 

Author Comment

by:mejaz01
ID: 6210897
I found out a better way to do that. So I just think it's nice to let you know as well

EXAMPLE

     ofstream outs;
     outs.open("somefile", ios::app);
     outs<<"AnyString"<<endl;
     outs.close();
*------------
so ios::app is the append mode:)))
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 176
List out all word 7 338
method notes when mouse over in eclipse 5 90
Smart Camera scanning and reading information 3 122
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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