Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC++
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 17: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 at 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
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2014
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