zoukankan      html  css  js  c++  java
  • fopen时w与wb的区别

        今天做了个小程序,把一个二进制文件分割为多个1.44M的文件,但分割完成后,发现很多文件的大小都超过1.44M。在网上搜索了下,发现时fopen是的参数部队。
        “w”表示为文本文件。用则会把文件中的“0A”变为“0D0A”,因为某些文件系统认为“0A”为文本文件的换行符,windows认为“0D0A”为文本文件的换行符,为了兼容其他文件系统(如从linux拷贝来的文件),windows上的fopen函数做了这样的格式转换。如果我记得没错的话,linux与vxworks上不会做这样的转换,所以可以说使用“w”,其属性要看所在的平台。
        “wb参数”表示为二进制文件,则样文件系统会按纯粹的二进制格式进行操作,因此也就不存在格式转换的问题了。
         综上,如果使用的是二进制文件,一定要使用“wb”参数,这样肯定错不了。
        
    参数“wt”:
        “w”其实默认就是“wt”,即write in text mode。下面是msdn中队这几个参数的解释:

    “If t or b is not given in mode, the default translation mode is defined by the global variable _fmode. ”

    “The default setting of _fmode is _O_TEXT for text-mode translation. _O_BINARY is the setting for binary mode.

    You can change the value of _fmodein either of two ways:

    • Link with BINMODE.OBJ. This changes the initial setting of _fmode to _O_BINARY, causing all files except stdin, stdout, and stderrto be opened in binary mode.
    • Change the value of _fmode directly by setting it in your program. ”
  • 相关阅读:
    Java HashMap的原理、扩容机制、以及性能
    Istanbul BFT共识算法解读
    golang中slice的扩容机制
    Use the "Enclave Signing Tool" to sign enclave files
    以太坊椭圆曲线Specp256k1通过消息的hash和签名(对消息的hash的签名)来恢复出公钥和计算r值
    Intel SGX SDK toolkits
    Intel SGX Edger8r
    Intel SGX C++ library
    SGX Makefile学习笔记
    在ubuntu中安装gem5
  • 原文地址:https://www.cnblogs.com/zhoug2020/p/2428918.html
Copyright © 2011-2022 走看看