fopen (), r+ w+ is a form of reading and writing, it is no difference

Source: Internet
Author: User
fopen (), r+ w+ are read and write mode, is not the difference?
fopen (),
r+
w+
It's all a read-write mode, isn't it different? Then why did you make 2 out of it?
It's best to write an example to see
------to solve the idea----------------------
R read-only opens, pointing the file pointer to the file header.
The "r+" read-write mode opens, pointing the file pointer to the file header.
The "W" Write method opens, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try to create it.
The "w+" read-write mode opens, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try to create it.
The "A" write opens, pointing the file pointer to the end of the file. If the file does not exist, try to create it.
A + read-write mode opens, pointing the file pointer to the end of the file. If the file does not exist, try to create it.

------to solve the idea----------------------
Like upstairs, r+ will point the file pointer to the file header. When you write to it, it's your new content + Original content

w+ also points the file pointer to the file header, but he will first empty the contents of the file before adding new content The result file contains only the newly added content
------to solve the idea----------------------
Study of the study
  • 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.