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

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

        时间:2023-08-28
          <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.

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

                  上一篇:exit() 和 abort() 有什么区别? 下一篇:如何处理或避免 C++ 中的堆栈溢出

                  相关文章

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

                  1. <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'>

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