I saw this example in cppreference's documentation for std::numeric_limits
#include <limits>
#include <iostream>
int main()
{
std::cout << "type\tlowest()\tmin()\t\tmax()\n\n";
std::cout << "uchar\t"
<< +std::numeric_limits<unsigned char>::lowest() << '\t' << '\t'
<< +std::numeric_limits<unsigned char>::min() << '\t' << '\t'
<< +std::numeric_limits<unsigned char>::max() << '\n';
std::cout << "int\t"
<< std::numeric_limits<int>::lowest() << '\t'
<< std::numeric_limits<int>::min() << '\t'
<< std::numeric_limits<int>::max() << '\n';
std::cout << "float\t"
<< std::numeric_limits<float>::lowest() << '\t'
<< std::numeric_limits<float>::min() << '\t'
<< std::numeric_limits<float>::max() << '\n';
std::cout << "double\t"
<< std::numeric_limits<double>::lowest() << '\t'
<< std::numeric_limits<double>::min() << '\t'
<< std::numeric_limits<double>::max() << '\n';
}
I don't understand the "+" operator in
<< +std::numeric_limits<unsigned char>::lowest()
I have tested it, replaced it with "-", and that also worked. What is the use of such a "+" operator?
+
? – Convoy-
then the outputs won't be the correct values for the limits – Hochman+
. In this case, your query would probably be "c++ unary plus". It's... not exactly intuitive, and you still have to learn to read the documentation that you'll find, but IMO it's a useful skill to cultivate. – Ranchero