Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (1 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

1 solution

C++
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.
 
Share this answer
 
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)



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