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