#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int n;
    char ch;

    while (true) 
    {
        cout << "输入一个int类型的整数:";
        // 如果输入非int类型
        if (!(cin >> n)) 
        {
       // 复位
       cin.clear();
       // 清空缓冲区 while ((ch = getchar()) != '\n') continue; // 打印错误信息 cout << "请输入int类型!!!" << endl; continue; } cout << "你输入的整数为:" << n << endl; } }

C++ 输入int类型出错处理

相关文章:

  • 2022-12-23
  • 2021-06-16
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-23
  • 2022-02-06
  • 2021-07-14
  • 2021-12-04
  • 2022-03-08
相关资源
相似解决方案