1. <tfoot id='ZjyPx'></tfoot>
    2. <small id='ZjyPx'></small><noframes id='ZjyPx'>

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

        <legend id='ZjyPx'><style id='ZjyPx'><dir id='ZjyPx'><q id='ZjyPx'></q></dir></style></legend>

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

        fstream 不会创建文件

        fstream won#39;t create a file(fstream 不会创建文件)
        <tfoot id='0dRst'></tfoot>

            <bdo id='0dRst'></bdo><ul id='0dRst'></ul>

            <small id='0dRst'></small><noframes id='0dRst'>

            • <legend id='0dRst'><style id='0dRst'><dir id='0dRst'><q id='0dRst'></q></dir></style></legend>
                <tbody id='0dRst'></tbody>

                <i id='0dRst'><tr id='0dRst'><dt id='0dRst'><q id='0dRst'><span id='0dRst'><b id='0dRst'><form id='0dRst'><ins id='0dRst'></ins><ul id='0dRst'></ul><sub id='0dRst'></sub></form><legend id='0dRst'></legend><bdo id='0dRst'><pre id='0dRst'><center id='0dRst'></center></pre></bdo></b><th id='0dRst'></th></span></q></dt></tr></i><div id='0dRst'><tfoot id='0dRst'></tfoot><dl id='0dRst'><fieldset id='0dRst'></fieldset></dl></div>
                  本文介绍了fstream 不会创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果文本文件不存在,我只是想创建一个文本文件,而且我似乎无法让 fstream 做到这一点.

                  I'm simply trying to create a text file if it does not exist and I can't seem to get fstream to do this.

                  #include <fstream>
                  using std::fstream;
                  
                  int main(int argc, char *argv[]) {
                      fstream file;
                      file.open("test.txt");
                      file << "test";
                      file.close();
                  }
                  

                  我是否需要在 open() 函数中指定任何内容才能让它创建文件?我已经读到你不能指定 ios::in ,因为这会期望一个已经存在的文件在那里,但我不确定是否需要为一个文件指定其他参数不存在.

                  Do I need to specify anything in the open() function in order to get it to create the file? I've read that you can't specify ios::in as that will expect an already existing file to be there, but I'm unsure if other parameters need to be specified for a file that does not already exist.

                  推荐答案

                  你应该像这样添加 fstream::out 到 open 方法:

                  You should add fstream::out to open method like this:

                  file.open("test.txt",fstream::out);
                  

                  有关 fstream 标志的更多信息,请查看此链接:http://www.cplusplus.com/reference/fstream/fstream/open/

                  More information about fstream flags, check out this link: http://www.cplusplus.com/reference/fstream/fstream/open/

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

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

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)

                    • <legend id='g0JKR'><style id='g0JKR'><dir id='g0JKR'><q id='g0JKR'></q></dir></style></legend>

                        • <bdo id='g0JKR'></bdo><ul id='g0JKR'></ul>
                            <tbody id='g0JKR'></tbody>

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

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

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