#include <iostream>
#include <sstream>
using namespace std;
bool IsNumbe(string str)
{
stringstream sin(str);
char c;
double d;
if(!(sin>>d))
{
return false;
}
if(sin>>c)
{
return false;
}
return true;
}
int main()
{
const char* lpStr = "123";
cout<<lpStr<<(IsNumbe(lpStr)==true?" is":" is not")<<" number"<<endl;
return 0;
#include <sstream>
using namespace std;
bool IsNumbe(string str)
{
stringstream sin(str);
char c;
double d;
if(!(sin>>d))
{
return false;
}
if(sin>>c)
{
return false;
}
return true;
}
int main()
{
const char* lpStr = "123";
cout<<lpStr<<(IsNumbe(lpStr)==true?" is":" is not")<<" number"<<endl;
return 0;
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <ctype.h>
#include <cstdio>
#include <cstring>
bool IsNumb(const char* lpStr)
{
int cnt = strlen(lpStr);
for(int i =0; i<cnt; i++)
{
if ( !isdigit(lpStr[i]) )
{
return false;
}
}
return true;
}
int main()
{
const char* lpStr = "1345d";
printf("%s is %s number!!\n", lpStr, IsNumb(lpStr)==true?"":"not");
return 0;
}