Click here to Skip to main content
12,954,403 members (64,809 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi all ,
I have a query , i need to write a code such that I need to open a file if it does not exist it should first create and then open . I wrote this way

CStdioFile file;
file.Open(_strDestination,CFile::modeReadWrite | CFile::typeText);
I wrote it this way but did not help .


Thanks in advance .
Posted 4-Nov-12 16:26pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

CStdioFile file;
file.Open(_strDestination, CFile::modeReadWrite | CFile::typeText | CFile::modeCreate | CFile::modeNoTruncate ); 


CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Furthermore, if the file being created already exists, the underlying file pointer will point to the beginning of the file. This flag guarantees the file to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.
  Permalink  
Comments
iampradeepsharma 4-Nov-12 22:51pm
   
thnx Santhosh !

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,524
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100