I'd do things a bit differently -- initialize a stringstream with the input, read an int, then check whether the stream is empty:
#include <sstream>
#include <iostream>
typedef char const *LPCSTR;
template <class T>
bool check_read(LPCSTR input, T &val) {
std::istringstream reader(input);
reader >> val;
char ch;
if (reader >> ch) {
std::cerr << "\nUnconverted character: " << ch << std::endl;
return false;
}
return true;
}
int main() {
LPCSTR inputs[] = {"12345", "54321a"};
int a;
for (int i=0; i<2; i++) {
check_read(inputs[i], a);
std::cout << "Converted: " << a << std::endl;
}
return 0;
}
Another reasonable possibility would be strtol or one of its cousins. These return a pointer to the first un-converted character (if any), so they tell you fairly directly what was and wasn't converted. They're faster but generally less flexible than streams -- for example, if you want to read a floating point number, the check_read above will work as-is, but something using strtol would need to be rewritten.
As yet one more possibility, you might consider Boost lexical_cast (which is packaged a little differently, but pretty similar to the code above).