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 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 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 Sergey Alexandrovich Kryukov 696
1 OriginalGriff 478
2 Tadit Dash 400
3 sanket saxena 337
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid