This is not exactly what you are asking but I am sure this will help you.
Code:
/* Number or alphabetes detection demo code */
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x = 0;
string badChars;
do {
cout << "Enter a number (-1 = quit): ";
if(!(cin >> x)) {
cin.clear();
cin >> badChars;
cout << "You typed string \"" << badChars << "\" instead of a number!" << endl;
cout << "Please try again." << endl;
} else if(x != -1) {
cout << "You entered digit!" << x << endl;
}
} while(x != -1);
cin.get();
return 0;
}