我该怎么做呢?我要它检查数字
cout<<"Enter your first number: ";
std::cin >> dblNumOne;
int i=0;
char str[]=dblNumkOne;
while (str[i])
{
if (isalpha(str[i])) printf ("character %c is alphabetic\n",str[i]);
else printf ("character %c is not alphabetic\n",str[i]);
i++;
}
最佳答案
很简单,只需像这样遍历std :: string:
std::string dblNumOne;
std::cin >> dblNumOne;
for(unsigned int i = 0; i < dblNumOne.length(); i++)
{
if (isalpha(dblNumOne[i]))
{
printf ("character %c is alphabetic\n", dblNumOne[i]);
}
else
{
printf ("character %c is not alphabetic\n", dblNumOne[i]);
}
}
关于c++ - C++如何将字符串转换为char数组并检查数字?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18777372/