I was trying to find an elegant way to check if a string is a number. Then I was very surprised that C++ doesn't have an off-the-shelf function for that. Mybe I missed somthing that's why I didn't know.
I found one solution I like:
With C++11 compiler, for non-negative integers I would use something like this (note the :: instead of std::):
bool is_number(const std::string &s) {
return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit);
}
But here I can't why it only works when there is :: before the isdigit. what does the :: do here?