Summary of file operations in the C + + standard library

Source: Internet
Author: User

1 stdio.h is the standard input and output library in the C standard library

2 methods that are called in C + +

Call it directly, but it's best to precede the function name with:: To show the inner function of the area classification and the C standard library function.

3 c use of standard input and output libraries

3.1 Core structure

File Structure Body

When you open a file, you get it, and then you don't have to worry about it.

3.2 Core Approach

3.2.1 Fopen

The first string is the path to the file.

The second argument is a string that represents the mode in which the file is manipulated, and "RB" means read binary, which reads the file in binary form.

3.2.2 Fseek

The first parameter is a file struct pointer.

The second parameter and the third parameter are used to set the position of the file read-write location pointer, where the third parameter is the origin, and the second parameter is the offset. Two parameters together with more flexibility to control the position of reading and writing position pointers.

The third argument can be Seek_set (the beginning of the file), Seek_end (the end of the file).

3.2.3 Ftell

Gets the position of the file read-write pointer, counting from 0. For example, if the file read-write pointer to the beginning of the file, then the return value of the function is 0.

The file read and write pointer before the data is already read, if the file read and write pointer is 0, then that is not started to read the data, if the file read and write pointer to Seek_end, then the document has been read. Therefore, the size of the file read-write pointer is the size of the data that has been read. If the file read-write pointer is seek_end, then the file is read, then the size of the file read-write pointer is the size of the file.

Summary of file operations in the C + + standard library

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.