首页 > 其他 > 详细

atoi函数编写

时间:2015-03-11 21:40:41      阅读:287      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<string>
using namespace std;
int ai(const char *p){
	bool negflag = false;
	int rs = 0;
	if(*p=='+'||*p=='-'){
		negflag=(*p=='-');
		p++;
	}
	while(isdigit(*p)){
		rs=rs*10+(*p-'0');
		p++;
	}
	if(negflag) rs=0-rs;
	return rs;
}
void main(){
	const char a[] ="123"; 
	int k;
	k=ai(a);
	cout<<k;
	system("pause");
}

atoi函数编写

原文:http://blog.csdn.net/eliza1130/article/details/44204801

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!