在学习C++过程中写了如下一串代码,调试过程中只有输入英文字母才会结束程序(跳出循环),按照我的理解只要输入的参数n不是string::size _ type就能跳出while循环了啊。
#include
using namespace std;
int main() {
const string hexdigits = "0123456789ABCDEFF";
cout << "please enter a series of number between 0 and 15\n"
<< "Separated by spaces. Hit Enter when finished: "
<< endl;
string result;
string::size_type n;
while (cin >> n)
if (n < hexdigits.size())
result += hexdigits[n];
cout << "your hex number is " << result << endl;
return 0;
}