【发布时间】:2013-06-12 07:26:26
【问题描述】:
在我编写的代码中,我接收一个字符串,检查它是否只包含十进制数字,然后将字符串转换为 int。但是,在我的代码中,atoi 返回一个 0,而不是作为 int 的字符串。谁能告诉我哪里搞砸了?
while (!sucess || 0 == Entries){
delete [] bufferptr;
buffer = nullptr;
buffer = new char [MAX];
bufferptr = buffer;
cin.getline(buffer, MAX, '\n');
while (*buffer){
if (isdigit(*buffer++)){
success = true;
} else {
success = false;
break;
}
}
if (success){
numEntries = atoi(buffer);
cout << endl << numEntries << endl;
}
}
【问题讨论】:
-
做一些调试,好吗? Stack Overflow 不是人工云调试服务。
标签: c++ pointers user-input atoi