ok, i been searching after this but with no good result
i would like to se if a string contains numbers only
i tried searching on this site but i found nothing good to be used
im totally new to c++ (begun today), however i do have experience with lua
This is an untested idea, but you could cast each char in the string to an int and use an IF statement to check if it's less than 10. For example:
1 2 3 4 5 6 7 8
string str = "3257fg";
for(int i = 0;i < (strlen(str) - 1);i++) {
if((int)str[i] < 10) {
// it is a number, so do some code
} else {
// it is not a number, do something else
}
}
The reason this works is because when you cast a char to an int, the resulting value is the ASCII value of the character. For example, if you cast "a" to an integer, the resulting value would be 97. The last ASCII digit is 9, so if the ASCII value is less than 10, it's a digit.
'strlen' : cannot convert parameter 1 from 'std::string' to 'const char *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called