g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
#include <errno.h>
...
cin >> str;
errno = 0 ;
double d = strtod(str.c_str(), NULL);
if (errno) {
cout << "Please, enter number.";
}
on wrong input errno stay 0.
EDITED:
Next works fine:
char *err;
double d = strtod(str.c_str(), &err);
if (strlen(err)) {
cout << "Please, enter number." << endl;
}
What kind of “wrong input”? According to the manpage,
errnois only set when the input is a number that is too large or too small to be stored in the data type, but not when the input isn’t a number at all.