Several ways (CC ++Windows) open

zhaozj2021-02-16  63

text:

For example, open "myfile.txt"

1. Traditional used in C

File * fp;

Char * fn = "myfile.txt";

FP = fopen (FN, "A ");

IF (fp! = null)

{

// USE File

}

Fclose (fp);

2, recommended in C

Ofstream of;

OF. OPEN ("MyFile.txt")

Of.close ()

This personal feeling is better than fopen, and the general use does not have to pay attention to so many parameters.

3. The createfile function used in WIN32.

On Windows, I feel that the use of the CreateFile series is more authentic, you have to take a closer look.

MSDN, each time you write a data block to the file, which is very common.

4, use CFILE in MFC

This is rarely used. Unclear, it may be convenient.

转载请注明原文地址:https://www.9cbs.com/read-22283.html

New Post(0)