So, I\'ve looked around and haven\'t been able to figure out what\'s going on with cin during my While loop. I\'m working through the book C++ Primer (5th edition) and I noticed
There is an easier way to do this:
const string hexdigits = "0123456789ABCDEF";
cout << "Enter a series of numbers between 0 and 15 separated by spaces. Hit ENTER when finished: " << endl;
string line;
string result;
if (getline(cin, line)) // get the whole line
{
istringstream iss(result); // break them by spaces
int i;
while (iss >> i)
{
result += hexdigits[i];
result += " ";
}
cout << "Your hex result: " << result << endl;
}
else
{
cout << "Error handling input!" << endl;
}
With your solution, you would need to press Ctrl-D to end the input.