C++ variable types limits

前端 未结 4 646
不思量自难忘°
不思量自难忘° 2020-12-10 04:00

here is a quite simple question(I think), is there a STL library method that provides the limit of a variable type (e.g integer) ?

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 05:02

    Use std::numeric_limits:

    // numeric_limits example
    // from the page I linked
    #include 
    #include 
    using namespace std;
    
    int main () {
      cout << boolalpha;
      cout << "Minimum value for int: " << numeric_limits::min() << endl;
      cout << "Maximum value for int: " << numeric_limits::max() << endl;
      cout << "int is signed: " << numeric_limits::is_signed << endl;
      cout << "Non-sign bits in int: " << numeric_limits::digits << endl;
      cout << "int has infinity: " << numeric_limits::has_infinity << endl;
      return 0;
    }
    

提交回复
热议问题