Then read the number as a string by using getline(cin, strInput);
Then, use a reverse iterator to check each digit and add it (e. g. by calling push_back) to the internal vector (or string) if ok. The input at first position (position 0 or last of reverse iteration alternatively can be a minus sign).
string::reverse_iterator ri;
for (ri = strInput.rbegin(); ri != strInput.rend(); ++ri)
{
char digit = *ri;
// now check the digit and if ok convert it to an 8bit integer
// by subtracting '0' and push it to the internal vector
// handle the *last* char separately as it could be a minus sign
// in that case you would *not* push it to the vector but set the
// minus member to true.
// you also might ignore leading spaces or a + sign.
...
}
What I'm having trouble with now is putting it all together, or simply implementing it all in code form. Could anyone give me a hand?
Bookmarks