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

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

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

      <legend id='a9elL'><style id='a9elL'><dir id='a9elL'><q id='a9elL'></q></dir></style></legend>
    1. <tfoot id='a9elL'></tfoot>
    2. 在 C++ 中创建文件

      时间:2023-08-26
    3. <tfoot id='3RIJn'></tfoot>

          <tbody id='3RIJn'></tbody>

        <small id='3RIJn'></small><noframes id='3RIJn'>

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

                问题描述

                我想用 C++ 创建一个文件,但我不知道该怎么做.例如,我想创建一个名为 Hello.txt 的文本文件.

                I want to create a file using C++, but I have no idea how to do it. For example I want to create a text file named Hello.txt.

                有人可以帮我吗?

                推荐答案

                一种方法是创建 ofstream 类的一个实例,并使用它来写入您的文件.这是一个网站链接,其中包含一些示例代码,以及有关大多数 C++ 实现可用的标准工具的更多信息:

                One way to do this is to create an instance of the ofstream class, and use it to write to your file. Here's a link to a website that has some example code, and some more information about the standard tools available with most implementations of C++:

                ofstream 参考

                为了完整起见,这里有一些示例代码:

                For completeness, here's some example code:

                // using ofstream constructors.
                #include <iostream>
                #include <fstream>  
                
                std::ofstream outfile ("test.txt");
                
                outfile << "my text here!" << std::endl;
                
                outfile.close();
                

                您想使用 std::endl 来结束您的行.另一种方法是使用 ' ' 字符.这两件事是不同的, std::endl 刷新缓冲区并立即写入您的输出,而 ' ' 允许输出文件将所有输出放入缓冲区,并可能稍后写入.

                You want to use std::endl to end your lines. An alternative is using ' ' character. These two things are different, std::endl flushes the buffer and writes your output immediately while ' ' allows the outfile to put all of your output into a buffer and maybe write it later.

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

                上一篇:如何检查文件是否是 gzip 压缩的? 下一篇:遗留 C/C++ 项目中的死代码检测

                相关文章

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

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

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

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

                    <tfoot id='EO3kY'></tfoot>