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

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

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

        • <bdo id='eIajp'></bdo><ul id='eIajp'></ul>
        <tfoot id='eIajp'></tfoot>
      1. freopen() 等效于 C++ 流

        时间:2023-10-18

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

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

              <legend id='LU0Ns'><style id='LU0Ns'><dir id='LU0Ns'><q id='LU0Ns'></q></dir></style></legend>
                <bdo id='LU0Ns'></bdo><ul id='LU0Ns'></ul>

                  <tfoot id='LU0Ns'></tfoot>
                  本文介绍了freopen() 等效于 C++ 流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当使用 c 风格的 i/o 编程时,我有时会使用 freopen() 重新打开 stdin 以进行测试,这样我就不必一遍又一遍地重新输入输入.我想知道 c++ i/o 流是否有等价物.另外,我知道我可以使用管道在命令行/终端/任何东西上重定向它,但我想知道是否有办法在我的代码中做到这一点(因为如你所见,我对cl/t/w).

                  When programming with c-style i/o I sometimes use freopen() to reopen stdin for testing purposes so that I don't have to retype the input over and over. I was wondering if there is an equivalent for c++ i/o streams. Also, I know that I can use pipes to redirect it on the command line/terminal/whateveritis but I was wondering if there was a way to do it inside my code (because as you can see, I'm not very knowledgeable about the cl/t/w).

                  推荐答案

                  freopen 也适用于 cincout.无需搜索新内容.

                  freopen also works with cin and cout. No need to search for something new.

                  freopen("input.txt", "r", stdin); // redirects standard input
                  freopen("output.txt", "w", stdout); // redirects standard output
                  
                  int x;
                  cin >> x; // reads from input.txt
                  cout << x << endl; // writes to output.txt
                  

                  来自 C++ 标准 27.3.1:

                  From C++ standard 27.3.1:

                  对象cin控制来自与对象stdin关联的流缓冲区的输入,在中声明.

                  The object cin controls input from a stream buffer associated with the object stdin, declared in <cstdio>.

                  所以根据标准,如果我们重定向stdin,它也会重定向cin.cout 反之亦然.

                  So according to the standard, if we redirect stdin it will also redirect cin. Vice versa for cout.

                  这篇关于freopen() 等效于 C++ 流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 cout 打印 0x0a 而不是 0xa? 下一篇:CLion C++ 无法读取/打开项目目录中的 .txt 文件

                  相关文章

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

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

                      <bdo id='wKvLP'></bdo><ul id='wKvLP'></ul>
                  1. <tfoot id='wKvLP'></tfoot>