int isInt(string theString) throw () { //destroy whitespace at beginning and end of string. theString = destroyWhitespace(theString); const string integerList("0123456789"); int start = 0; bool negative = false; const int maxListIndex = integerList.length()-1; const int maxStringIndex = theString.length()-1; //check for minus or plus at beginning of integer. try { if(theString.at(0) == '-') { start = 1; negative = true; } else if(theString.at(0) == '+') { start = 1; } } catch(...) { throw; } //Loops through valid digits to check. int index = start; while( index <= maxStringIndex ) { bool match = false; try { for( int j = 0; (match == false) && (j <= maxListIndex); j++ ) { if(theString.at(index) == integerList.at(j)) { match = true; } } if (match == false) { throw string("String is not a valid integer."); } } catch(...) { throw; } index++; } //Construct number. int number; int factor; try { number = theString.at(maxStringIndex) - '0'; factor = 1; for(index = maxStringIndex-1; index >= start; index--) { factor *= 10; number += factor * (theString.at(index)-'0'); } } catch(...) { throw; } //Change negative if needed. if(negative == true) number *= -1; return number; }