C++は1文字列の中ですべて数字かどうかを判断します
4304 ワード
#include
#include
using namespace std;
bool IsdigitAll(string str)
{
for (int i = 0; i<str.size(); i++)
{
if (!isdigit(str[i]))
{
cout << str << " is not all digit" << endl;
return false;
}
}
return true;
}
int main()
{
string str = "123456789";
if (IsdigitAll(str))
{
cout << str << " is all digit" << endl;
}
str = "123456789abcdef";
if (IsdigitAll(str))
{
cout << str << " is all digit" << endl;
}
return 0;
}
出力:
123456789 is all digit
123456789abcdef is not all digit