MFC: Xinxin Sun Tutorial 12 notes

Source: Internet
Author: User

This lesson is mainly about file manipulation.

One. Write a file

1. Add an item to the menu and generate the corresponding message response function

2. Increase in response function Onwrite:

Method 1:

FILE *pfile = fopen ("1.txt", "w");

Fwrite ("http://www.panda.org", 1, strlen ("http://www.panda.org"), pFile);

Fclose (PFile);

If you do not want to close the file, you can use Fflush (pFile);

If you want to move the file pointer to the beginning to write data, you can use Fseek (pFile, 0, Seek_set);

Method 2:

Method 3:

Method 4:

Two. Read file

The previous operation is almost like writing a file.

Method 1:

FILE *pfile = fopen ("1.txt", "R");

Char ch[100];

memset (CH, 0, 100);

Fread (CH, 1, h, pFile);

MessageBox (CH);

Fclose (PFile);

Method 2:

FILE *pfile = fopen ("1.txt", "R");

Char *pbuf;
Fseek (pFile, 0, seek_end);
int len = Ftell (pFile);
PBuf = new Char[len+1];
Rewind (PFile);
Fread (PBuf, 1, Len, pFile);
Pbuf[len] = 0;
MessageBox (PBUF);
Fclose (PFile);

Method 3:

Method 4:

MFC: Xinxin Sun Tutorial 12 notes

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.