I'm trying to write a function that checks if a string contains a number, positive or negative.
getline(cin,line);
istringstream sin(line);
while (sin >> ws >> in){
if(all_of(in.begin(), in.end(), ::isdigit){
//do something with number
}
Problem is, isdigit() will set all negative numbers as not numbers. What other ways are there to check whether a string contains numbers?
Sample input: 1 2 -2 asdf 4.