Solved

Append mode?

Posted on 2001-06-19
3
493 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
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 105
bigDiff challenge 17 112
pre4 challenge 19 100
mapBully challenge 6 136
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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