str to int 转换

#include "stdafx.h"
#include "iostream"
#include "cassert"
using namespace std;

long int str_to_int(char * str)
{
	assert(str != NULL);
	long int sum = 0;
	char flag = '0';
	if(*str == '+')
	{
		flag = '+';
		str++;
	}
	else if (*str == '-')
	{
		flag = '-';
		str++;
	}
	
	while (*str != '\0' && *str >= '0' && *str <= '9')
	{
		if((sum -(*str - '0'))> std::numeric_limits::max()/10)//溢出检查
		{
			sum = 0;
			cout<<"overflow!"<::max()<

你可能感兴趣的:(C语言编程)