• <tfoot id='rqK5g'></tfoot>

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

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

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

      • <bdo id='rqK5g'></bdo><ul id='rqK5g'></ul>
      1. 如何从C ++中的cin读取直到EOF

        时间:2023-10-07
        • <small id='B3BrQ'></small><noframes id='B3BrQ'>

          • <tfoot id='B3BrQ'></tfoot>

                  <tbody id='B3BrQ'></tbody>
              1. <legend id='B3BrQ'><style id='B3BrQ'><dir id='B3BrQ'><q id='B3BrQ'></q></dir></style></legend>

                  <bdo id='B3BrQ'></bdo><ul id='B3BrQ'></ul>
                  <i id='B3BrQ'><tr id='B3BrQ'><dt id='B3BrQ'><q id='B3BrQ'><span id='B3BrQ'><b id='B3BrQ'><form id='B3BrQ'><ins id='B3BrQ'></ins><ul id='B3BrQ'></ul><sub id='B3BrQ'></sub></form><legend id='B3BrQ'></legend><bdo id='B3BrQ'><pre id='B3BrQ'><center id='B3BrQ'></center></pre></bdo></b><th id='B3BrQ'></th></span></q></dt></tr></i><div id='B3BrQ'><tfoot id='B3BrQ'></tfoot><dl id='B3BrQ'><fieldset id='B3BrQ'></fieldset></dl></div>
                  本文介绍了如何从C ++中的cin读取直到EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在编写一个直接从用户输入读取数据的程序,我想知道我如何(没有循环)从标准输入读取所有数据直到 EOF.我正在考虑使用 cin.get( input, '' )'' 并不是真正的 EOF 字符,它只是读取到 EOF 或 '',以先到者为准.

                  I am coding a program that reads data directly from user input and was wondering how could I (without loops) read all data until EOF from standard input. I was considering using cin.get( input, '' ) but '' is not really the EOF character, that just reads until EOF or '', whichever comes first.

                  还是使用循环是唯一的方法?如果是这样,最好的方法是什么?

                  Or is using loops the only way to do it? If so, what is the best way?

                  推荐答案

                  stdin 读取可变数量数据的唯一方法是使用循环.我一直发现 std::getline() 函数效果很好:

                  The only way you can read a variable amount of data from stdin is using loops. I've always found that the std::getline() function works very well:

                  std::string line;
                  while (std::getline(std::cin, line))
                  {
                      std::cout << line << std::endl;
                  }
                  

                  默认 getline() 读取直到换行.您可以指定一个替代终止字符,但 EOF 本身并不是一个字符,因此您不能简单地调用一次 getline().

                  By default getline() reads until a newline. You can specify an alternative termination character, but EOF is not itself a character so you cannot simply make one call to getline().

                  这篇关于如何从C ++中的cin读取直到EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何确保 std::random_shuffle 总是产生不同的结果? 下一篇:basic_ios 上标志的语义

                  相关文章

                  最新文章

                      <bdo id='KJ8sK'></bdo><ul id='KJ8sK'></ul>

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

                    1. <small id='KJ8sK'></small><noframes id='KJ8sK'>

                    2. <tfoot id='KJ8sK'></tfoot>