<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++ 流

        freopen() equivalent for c++ streams(freopen() 等效于 C++ 流)

      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++ 流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                  <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>
                            <tbody id='wKvLP'></tbody>
                        • <tfoot id='wKvLP'></tfoot>