<bdo id='OyTi0'></bdo><ul id='OyTi0'></ul>
  1. <tfoot id='OyTi0'></tfoot>
  2. <small id='OyTi0'></small><noframes id='OyTi0'>

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

      如何表示循环中不再有字符串 ss 的输入 while (cin &gt;&gt; ss)

      时间:2023-08-25
          <bdo id='gFnSx'></bdo><ul id='gFnSx'></ul>
          <legend id='gFnSx'><style id='gFnSx'><dir id='gFnSx'><q id='gFnSx'></q></dir></style></legend>

          <tfoot id='gFnSx'></tfoot>

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

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

                  <tbody id='gFnSx'></tbody>
              1. 本文介绍了如何表示循环中不再有字符串 ss 的输入 while (cin &gt;&gt; ss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我使用cin"从输入流中读取单词,例如

                I used "cin" to read words from input stream, which like

                int main( ){
                     string word;
                     while (cin >> word){
                         //do sth on the input word
                     }
                
                    // perform some other operations
                }
                

                代码结构与上面类似.它是可编译的.在执行过程中,我不断输入类似

                The code structure is something like the above one. It is compilable. During the execution, I keep inputting something like

                aa bb cc dd
                

                我的问题是如何结束这个输入?换句话说,假设文本文件只是aa bb cc dd".但是我不知道如何让程序知道文件结束了.

                My question is how to end this input? In other words, suppose the textfile is just "aa bb cc dd". But I do not know how to let the program know that the file ends.

                推荐答案

                您的代码是正确的.如果是交互式输入,则需要发送 EOF 字符,例如 CTRL-D.

                Your code is correct. If you were interactively inputting, you would need to send a EOF character, such as CTRL-D.

                读取文件时不需要此 EOF 字符.这是因为一旦到达输入流的末尾,cin"就没有任何剩余(因为流现在已关闭),因此 while 循环退出.

                This EOF character isn't needed when you are reading in a file. This is because once you hit the end of your input stream, there is nothing left to "cin"(because the stream is now closed), thus the while loop exits.

                这篇关于如何表示循环中不再有字符串 ss 的输入 while (cin &gt;&gt; ss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为什么 std::fstream 类不采用 std::string? 下一篇:fstream 不会创建文件

                相关文章

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

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

                    <tfoot id='b6uAs'></tfoot>
                    • <bdo id='b6uAs'></bdo><ul id='b6uAs'></ul>
                    <legend id='b6uAs'><style id='b6uAs'><dir id='b6uAs'><q id='b6uAs'></q></dir></style></legend>