Fopen () and r + w + are both read and write modes. isn't there any difference?

Source: Internet
Author: User
Fopen () and r + w + are both read and write modes. isn't there any difference? Fopen (),
R +
W +
It's all in read/write mode. isn't there any difference? So why do we need to generate two?
You 'd better write an instance to check it out.


Reply to discussion (solution)

R "open in read-only mode. point the file pointer to the file header.
Open the "r +" read/write mode and point the file pointer to the file header.
Open the "w" write mode, point the file pointer to the file header, and cut the file size to zero. If the file does not exist, try to create it.
Open in "w +" read/write mode, point the file pointer to the file header, and cut the file size to zero. If the file does not exist, try to create it.
"A" is opened in writing mode, pointing the file pointer to the end of the file. If the file does not exist, try to create it.
Open the "a +" read/write mode and point the file pointer to the end of the file. If the file does not exist, try to create it.

As mentioned above, r + points the file pointer to the file header. At this time, when you write it in, it is the newly added content + the original content.

W + also points the file pointer to the file header, but it first clears the content before the file, and then adds the new content. The result file only contains the newly added content.

I learned

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.