#include<iostream>
#include<tchar.h>
#include<string.h>
using namespace std;
int StrIntoInt( const char* str);
void main()
{
char A[100];
cout<<"请输入数字串";
cin>>A;
cout<<StrIntoInt(A);
system("pause");
}
int StrIntoInt(const char *str)
{
int number=0;
bool T=false;
int Len=strlen(str);
if(str[0]=='-'||str[0]=='+')
{
if(str[0]=='-')
T=true;
}
for(int i=0;i<Len;i++)
{
if(i==0)
if(T)
i=1;
if((str[i]>='0'&&str[i]<='9'))
{
number=number*10+(str[i]-'0');
}
else
{
break;
}
}
if(T)
return -number;
else
return number;
}
字符串转为数字
最新推荐文章于 2021-08-27 17:12:54 发布