<legend id='9lNWc'><style id='9lNWc'><dir id='9lNWc'><q id='9lNWc'></q></dir></style></legend>
<tfoot id='9lNWc'></tfoot>
    <bdo id='9lNWc'></bdo><ul id='9lNWc'></ul>

  • <small id='9lNWc'></small><noframes id='9lNWc'>

      <i id='9lNWc'><tr id='9lNWc'><dt id='9lNWc'><q id='9lNWc'><span id='9lNWc'><b id='9lNWc'><form id='9lNWc'><ins id='9lNWc'></ins><ul id='9lNWc'></ul><sub id='9lNWc'></sub></form><legend id='9lNWc'></legend><bdo id='9lNWc'><pre id='9lNWc'><center id='9lNWc'></center></pre></bdo></b><th id='9lNWc'></th></span></q></dt></tr></i><div id='9lNWc'><tfoot id='9lNWc'></tfoot><dl id='9lNWc'><fieldset id='9lNWc'></fieldset></dl></div>

      1. 使用/不使用 ios::binary 模式打开流时使用读/写的区别

        Difference in using read/write when stream is opened with/without ios::binary mode(使用/不使用 ios::binary 模式打开流时使用读/写的区别)
        <i id='JTiwO'><tr id='JTiwO'><dt id='JTiwO'><q id='JTiwO'><span id='JTiwO'><b id='JTiwO'><form id='JTiwO'><ins id='JTiwO'></ins><ul id='JTiwO'></ul><sub id='JTiwO'></sub></form><legend id='JTiwO'></legend><bdo id='JTiwO'><pre id='JTiwO'><center id='JTiwO'></center></pre></bdo></b><th id='JTiwO'></th></span></q></dt></tr></i><div id='JTiwO'><tfoot id='JTiwO'></tfoot><dl id='JTiwO'><fieldset id='JTiwO'></fieldset></dl></div>
        • <legend id='JTiwO'><style id='JTiwO'><dir id='JTiwO'><q id='JTiwO'></q></dir></style></legend>

            • <bdo id='JTiwO'></bdo><ul id='JTiwO'></ul>

            • <tfoot id='JTiwO'></tfoot>

                    <tbody id='JTiwO'></tbody>

                  <small id='JTiwO'></small><noframes id='JTiwO'>

                  本文介绍了使用/不使用 ios::binary 模式打开流时使用读/写的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我使用以下代码片段的实验中,我没有发现任何特别的区别,无论是使用还是不使用 ios:binary 模式创建流:

                  In my experiments with the following code snippet, I did not find any particular difference whether i created the streams with/without the ios:binary mode:

                  int main()
                  {
                      ifstream ostr("Main.cpp", ios::in | ios::binary | ios::ate);
                      if (ostr.is_open())
                      {
                          int size = ostr.tellg();
                          char * memBlock = new char[size + 1];
                          ostr.seekg(0, ios::beg);
                          ostr.read(memBlock, size);
                          memBlock[size] = '';
                          ofstream file("trip.cpp", ios::out | ios::binary);
                          file.write(memBlock, size);
                          ostr.close();
                      }
                  }
                  

                  在这里,我试图将原始源文件复制到另一个具有不同名称的文件中.

                  Here I am trying to copy the original source file into another file with a different name.

                  我的问题是在使用/不使用 ios::binary 模式打开 fstream 对象时,读/写调用(与二进制文件 IO 相关联)有什么区别?使用二进制模式有什么好处吗?文件IO什么时候用什么时候不用?

                  My question is what is the difference between the read/write calls(which are associated with binary file IO) when an fstream object is opened with/without ios::binary mode ? Is there any advantage of using the binary mode ? when to and when not to use it when doing file IO ?

                  推荐答案

                  binarytext 模式之间的唯一区别是如何处理 ' ' 字符.

                  The only difference between binary and text mode is how the ' ' character is treated.

                  binary 模式下,没有 翻译.

                  text模式下 在写入时被翻译成行尾.
                  text 模式下,end of line sequence 在读取时被翻译成 .

                  In text mode is translated on write into a the end of line sequence.
                  In text mode end of line sequence is translated on read into .

                  行尾是平台相关的.

                  示例:

                  LF    ('x0A'):      Multics, Mac OS X, BeOS, Amiga, RISC OS
                  CRLF  ('x0Dx0A'): Microsoft Windows, DEC TOPS-10, RT-11
                  CR:   ('x0D'):      TRS-80, Mac OS Pre X
                  RS:   ('x1E'):      QNX pre-POSIX implementation.
                  

                  这篇关于使用/不使用 ios::binary 模式打开流时使用读/写的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                  <small id='sizPD'></small><noframes id='sizPD'>

                1. <i id='sizPD'><tr id='sizPD'><dt id='sizPD'><q id='sizPD'><span id='sizPD'><b id='sizPD'><form id='sizPD'><ins id='sizPD'></ins><ul id='sizPD'></ul><sub id='sizPD'></sub></form><legend id='sizPD'></legend><bdo id='sizPD'><pre id='sizPD'><center id='sizPD'></center></pre></bdo></b><th id='sizPD'></th></span></q></dt></tr></i><div id='sizPD'><tfoot id='sizPD'></tfoot><dl id='sizPD'><fieldset id='sizPD'></fieldset></dl></div>
                  <legend id='sizPD'><style id='sizPD'><dir id='sizPD'><q id='sizPD'></q></dir></style></legend>
                    <tbody id='sizPD'></tbody>
                    <bdo id='sizPD'></bdo><ul id='sizPD'></ul>

                    <tfoot id='sizPD'></tfoot>