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

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

        整数的用户输入 - 错误处理

        User Input of Integers - Error Handling(整数的用户输入 - 错误处理)
          <tbody id='74gll'></tbody>
            <bdo id='74gll'></bdo><ul id='74gll'></ul>

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

            <small id='74gll'></small><noframes id='74gll'>

            <tfoot id='74gll'></tfoot>

              • <legend id='74gll'><style id='74gll'><dir id='74gll'><q id='74gll'></q></dir></style></legend>

                  本文介绍了整数的用户输入 - 错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的程序的某些输入区域有问题.用户输入特定整数的部分有几个部分.即使他们输入了错误的,也很好,但我注意到如果他们输入了任何非整数类型的东西,比如m",那么它会重复循环错误消息.

                  I'm having some trouble with certain input areas of my program. There are a few parts where the user inputs a specific integer. Even if they enter the wrong one that's all fine and dandy, but I noticed if they enter anything not of integer type like 'm' then it will loop the error message repeatedly.

                  我有几个具有整数输入的函数.这是一个示例.

                  I have a couple functions that have integer input in them. Here's one for an example.

                  void Room::move(vector<Room>& v, int exone, int extwo, int exthree, int current)
                  {
                      v[current].is_occupied = false;
                      int room_choice;
                      cout << "
                  Enter room to move to: ";
                      while(true)
                      {
                          cin >> room_choice;
                          if(room_choice == exone || room_choice == extwo || room_choice == exthree)
                          {
                              v[room_choice].is_occupied = true;
                              break;
                          }
                          else cout << "Incorrect entry. Try again: ";
                      }
                  }
                  

                  推荐答案

                  您可以使用 cin.good()cin.fail() 来判断 cin 是否可以成功处理提供的输入值.如有必要,您可以在继续处理之前使用 cin.clear() 清除错误状态.

                  You can use cin.good() or cin.fail() to determine whether cin could successfully deal with the input value provided. You can then use cin.clear(), if necessary, to clear the error state before continuing processing.

                  这篇关于整数的用户输入 - 错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

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

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

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

                            <tbody id='NF1Ir'></tbody>
                          <tfoot id='NF1Ir'></tfoot>