相关疑难解决方法(0)

我为什么不#include <bits/stdc ++.h>?

我在我的代码中发布了一个问题,其唯一的#include指令如下:

#include <bits/stdc++.h>
Run Code Online (Sandbox Code Playgroud)

我的老师告诉我这样做,但在评论部分,我被告知我不应该这样做.

为什么?

c++ portability c++-faq turbo-c++ implementation-defined-behavior

215
推荐指数
6
解决办法
2万
查看次数

检查cin输入流会产生一个整数

我输入了这个,它要求用户输入两个整数,然后变成变量.从那里它将执行简单的操作.

如何让计算机检查输入的内容是否为整数?如果没有,请让用户键入一个整数.例如:如果有人输入"a"而不是2,那么它会告诉他们重新输入一个数字.

谢谢

 #include <iostream>
using namespace std;

int main ()
{

    int firstvariable;
    int secondvariable;
    float float1;
    float float2;

    cout << "Please enter two integers and then press Enter:" << endl;
    cin >> firstvariable;
    cin >> secondvariable;

    cout << "Time for some simple mathematical operations:\n" << endl;

    cout << "The sum:\n " << firstvariable << "+" << secondvariable 
        <<"="<< firstvariable + secondvariable << "\n " << endl;

}
Run Code Online (Sandbox Code Playgroud)

c++ cin

13
推荐指数
1
解决办法
14万
查看次数