C++ Infinity: Using std::numeric_limits
In C++, there is no built-in “inf” function. However, you can use “std::numeric_limits” from the standard math library to obtain the value for infinity. Here is an example code:
#include <iostream>
#include <limits>
int main() {
double inf = std::numeric_limits<double>::infinity();
std::cout << "无穷大值:" << inf << std::endl;
return 0;
}
Output:
无穷大值:inf
In this example, we are using the std::numeric_limits::infinity() function to obtain the infinity value of the double data type. The value of infinity will be displayed as “inf”.