Cfile: modenotruncate parameter description

Source: Internet
Author: User

On msdn:

Cfile: modenotruncate combine this value with modecreate. if the file being created already exists, it is not truncated to 0 length. thus the file is guaranteed 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.

It means to create and open a file in modecreate mode. If the file already exists, the existing file will be cleared and modenotruncate will not be cleared. For example, if the original file is 80 K long, you need to write 50 K data. In general modecreate mode, the file length is reset to 0 first, and then 50 k Data is written. If the file length is 50 K, 50 k Data is directly written using cfile: modenotruncate, the final file length is still 80 KB. The data is the first 50 K of new data and the last 30 K of old data.

In MFC, The append data is also relatively simple, as if to set the cfile: modenotruncate parameter. In this example, file operations and reading/writing are performed in the cstdiofile class. However, there seems to be no simple method, so I can see this on the Internet:

Cstdiofile file (strfile, cfile: modecreate | cfile: modenotruncate | cfile: modewrite );

File. writestring (strtmp );

File. close;

Modenotruncate means not to intercept

However, I tried this code and it didn't work. I don't know why.

Therefore, before writing a string to writestring, you can add a code that first locates the pointer at the end of the file.

Cstring strtmp = "hehe/R/N ";

Cstdiofile file (strfile, cfile: modecreate | cfile: modenotruncate | cfile: modewrite );

File. seektoend (); // first locate to the end of the file

File. writestring (strtmp );

File. close;

I 've been playing with the file operations related to MFC over the past few days. For the cfilestatus of the day before yesterday, please refer to the detailed instructions on the use of cfilestatus. These codes are all prepared for the next version of the fliggy book, A Xiang is also studying the implementation of P2P technology, and soon the Flying Pigeon will become a powerful instant messaging software.

 

References:

Http://blog.163.com/cyin8@126/blog/static/172796962009727102249186/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.