If the string is all numbers
Quote:Is there a standard way to tell if a string consists of all numbers or not?
Here is how I would do it.
bool IsStringNumeric( std::string str ){ for( UINT i = 0; i < str.size(); i++ ) { if( str < 48 || str > 57 ) return false; } return true;}
Then again, I'm sure there is some easier way I'm not thinking off.
Disclaimer: This may not work, I just came up with it.
You could just go through the stream and check -
There may also be a way to do it using stringstreams.
EDIT: oops, beaten to it [wink]
for ( std::string::iterator itor = myString.begin(); itor != myString.end(); itor++ ) if ( *itor < '0' || *itor > '9' ) return false;return true;
There may also be a way to do it using stringstreams.
EDIT: oops, beaten to it [wink]
Didn't you already post a topic like this????
Anyways this is untested code:
Anyways this is untested code:
template <typename _E>bool is_all_numbers(const std::basic_string<_E>& Str){ for (size_t i = 0;i < Str.length();i++) { if (Str < (_E) '0' || Str > (_E) '9') { return false; } } return true;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement