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

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

    <tfoot id='0zfox'></tfoot>
    1. <legend id='0zfox'><style id='0zfox'><dir id='0zfox'><q id='0zfox'></q></dir></style></legend>

      1. C++:ofstream 类将文件保存到哪里?

        时间:2023-10-18

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

            <tfoot id='r944y'></tfoot>
              <bdo id='r944y'></bdo><ul id='r944y'></ul>

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

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

                  <tbody id='r944y'></tbody>

                • 本文介绍了C++:ofstream 类将文件保存到哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我从 Windows 迁移到 Mac,现在我遇到了文件输入/输出类的问题:ifstream &ofstream.

                  I moved from Windows to Mac and now I'm experiencing a problem with the file input/output classes: ifstream & ofstream.

                  在 Windows 中使用 g++/代码块运行时

                  In Windows when you run with g++/Code Blocks

                  ofstream out("output.txt");
                  out << "TEST";
                  out.close();
                  

                  一个新文件output.txt"将在同一目录中创建.

                  A new file "output.txt" will be created in the same directory.

                  但是在 MAC OS X 中,这个文件是在我的主目录中创建的:/Users/USER_NAME/output.txt

                  However in MAC OS X, this file is created in my home directory: /Users/USER_NAME/output.txt

                  我怎样才能把这个文件和可执行文件放在同一个目录下?

                  How can I have this file in the same directory together with the executable?

                  附言我正在使用 GCC 和 CodeBlocks.没有项目 - 我只是编译一个源文件.

                  P.S. I'm using GCC and CodeBlocks. There are no projects - I'm just compiling a single source file.

                  推荐答案

                  流类与所有其他文件打开函数一样,在您提供相对路径时使用当前目录.您可以使用像 chdir 这样的函数来控制当前目录,但更好的解决方案是使用完全限定的文件名.然后删除程序对当前目录的依赖.

                  The stream classes, like all other file-opening functions, use the current directory when you provide a relative path. You can control the current directory with a function like chdir, but a better solution is to use fully qualified file names. Then you remove your program's dependency on the current directory.

                  这篇关于C++:ofstream 类将文件保存到哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么按位移位(&lt;&lt; 和 &gt;&gt;)用于 cout 和 cin? 下一篇:如何使用 cout 打印 0x0a 而不是 0xa?

                  相关文章

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

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

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

                      • <bdo id='P4uS2'></bdo><ul id='P4uS2'></ul>
                    1. <tfoot id='P4uS2'></tfoot>