Determine if a string is numeric: Difference between revisions

Line 264:
 
=={{header|C++}}==
Using stringstream:
<lang cpp>#include <sstream> // for istringstream
 
Line 292 ⟶ 293:
return ( iss.rdbuf()->in_avail() == 0 );
}
</lang>
 
Using find:
/* OR */
<lang cpp>
 
bool isNumeric( const char* pszInput, int nNumberBase )
{
Line 301 ⟶ 303:
 
return (input.find_first_not_of(base.substr(0, nNumberBase)) == string::npos);
}
</lang>
 
Using all_of (requires C++11)
<lang cpp>
bool isNumeric(std::string input) {
return std::all_of(input.begin(), input.end(), ::isdigit);
}
</lang>
Anonymous user