基本c++输入问题

Basic C++ Input Issue

本文关键字:问题 输入 c++ 基本      更新时间:2023-10-16

在(cin <<)输入),永远不会用到if语句。

我在while循环之外运行代码,它似乎可以工作。有人能帮忙吗?

#include <iostream>
using namespace std;
int main() {
   int input = 0;
   bool stop = false;
   while(!stop) {
      while( input == 0 ) {
         cout << "Enter the radix (-1 to exit): ";
         cin >> input;
         if (input == 2) {
            cout << "foo";
         } else {
            cout << "bar";
         }
      }
   }
}

谢谢!

编辑:固定!显然我忘了"冲"牌了。所以我需要一个"count <<"结束"after"cin <<输入"。

考虑你的循环。你有

while(!stop) 
{
    //do stuff but never change stop
}

所以它永远不会退出循环