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

        <small id='9VcYr'></small><noframes id='9VcYr'>

      1. std::fstream 不创建文件

        std::fstream doesn#39;t create file(std::fstream 不创建文件)
        • <bdo id='6zO0F'></bdo><ul id='6zO0F'></ul>

              <tbody id='6zO0F'></tbody>
            <i id='6zO0F'><tr id='6zO0F'><dt id='6zO0F'><q id='6zO0F'><span id='6zO0F'><b id='6zO0F'><form id='6zO0F'><ins id='6zO0F'></ins><ul id='6zO0F'></ul><sub id='6zO0F'></sub></form><legend id='6zO0F'></legend><bdo id='6zO0F'><pre id='6zO0F'><center id='6zO0F'></center></pre></bdo></b><th id='6zO0F'></th></span></q></dt></tr></i><div id='6zO0F'><tfoot id='6zO0F'></tfoot><dl id='6zO0F'><fieldset id='6zO0F'></fieldset></dl></div>
          • <legend id='6zO0F'><style id='6zO0F'><dir id='6zO0F'><q id='6zO0F'></q></dir></style></legend>
            <tfoot id='6zO0F'></tfoot>
          • <small id='6zO0F'></small><noframes id='6zO0F'>

                  本文介绍了std::fstream 不创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将 std::fstream 用于 io to file,如果文件不存在,我想创建该文件.

                  I am trying to use std::fstream for io to file, and I want to create the file if it doesn't already exist.

                    std::fstream my_stream
                    my_stream.open("my_file_name",std::fstream::binary | std::fstream::in | std::fstream::out);
                    if(!my_stream)
                        std::cout<<"error"<<strerror(errorno);
                  

                  我得到这个结果:没有这样的文件或目录."

                  I get this result: "No such file or directory."

                  在这种情况下如何创建文件?

                  How can I create the file in this case?

                  推荐答案

                  您在调用 fstream::open().这是已知强制它需要现有文件.

                  You're specifying std::fstream::in in your call to fstream::open(). This is known to force it to require an existing file.

                  从你的 mode 参数中删除 std::fstream::in,或者指定 std::fstream::trunc 除了其他标志.

                  Either remove std::fstream::in from your mode argument, or specify std::fstream::trunc in addition to the other flags.

                  这篇关于std::fstream 不创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                  vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                  C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                  Adding types to the std namespace(将类型添加到 std 命名空间)
                  Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                  How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)
                  <legend id='v6Du0'><style id='v6Du0'><dir id='v6Du0'><q id='v6Du0'></q></dir></style></legend>

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

                        <tbody id='v6Du0'></tbody>

                        <bdo id='v6Du0'></bdo><ul id='v6Du0'></ul>