码迷,mamicode.com
首页 > 其他好文 > 详细

atoi函数编写

时间:2015-03-11 21:43:30      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:c++

#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函数编写

标签:c++

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!