Search code examples
cfile-iofopen

Difference between r+b and rb+ (or w+b and wb+)


While reading or writing to file in binary mode, what's the difference between putting '+' between 'r'/'w' and 'b' or putting it right after them both?

I searched and i foud that this affects the behavoir of reading/writing to the file but i don't understand what that means...


Solution

  • From the C Standard (7.21.5.3 The fopen function)

    r+b or rb+ open binary file for update (reading and writing)

    So there is no difference in specifying the mode.

    Here are some other equivalent mode specifications

    w+b or wb+ truncate to zero length or create binary file for update

    w+bx or wb+x create binary file for update

    a+b or ab+ append; open or create binary file for update, writing at end-of-file