Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How can I create Files in appending mode. I need to reuse the same file
whenever the application works.Help me to find it.

Thanks
Mithun Nair
Posted

Use the CFile class and use the flag CFile::modeNoTruncate.

Have a look here for more info:
http://msdn.microsoft.com/en-us/library/cz0a83sb%28v=vs.80%29.aspx[^]

Good luck!
 
Share this answer
 
Comments
fjdiewornncalwe 7-Jan-11 10:22am    
Just to be a little more specific.
file.Open(lpszfileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite)
+5...
E.F. Nijboer 7-Jan-11 11:51am    
Nice additional information :-D
Member 9274864 6-Sep-12 6:39am    
Hi i used the same method iam not able to append the data in the excel sheet,can you kindly suggest how to do it ,below is my code

CCSVFile::CCSVFile(LPCTSTR lpszFilename, Mode mode)
: CStdioFile(lpszFilename, (mode == modeRead) ?
CFile::modeRead|CFile::shareDenyWrite|CFile::typeText
:
CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite)

{
The file streams from The Standard C++ Library are also an option.
They don't require MFC (CFile does) and they are not OS specific (CreateFile and SetFilePointerEx are Windows specific APIs).

You can use std::ofstream[^].
See the documentation for std::ofstream::open[^] and. You can use something like:
std::ofstream myfilebin, myfiletxt;

// For binary files
myfilebin.open ("example.bin", std::ios::out | std::ios::app | std::ios::binary);

// For text files
myfiletxt.open ("example.txt", std::ios::out | std::ios::app);


For additional details refer to this[^] article.
 
Share this answer
 
v2
You can also use the CreateFile[^] and the SetFilePointerEx[^] Windows API functions.

Regards
Espen Harlinn
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900