atoi和stoi

 
  
vs环境下:
stoi函数默认要求输入的参数字符串是符合int范围的[-2147483648, 2147483647],否则会runtime error。
atoi函数则不做范围检查,若超过int范围,则显示-2147483648(溢出下界)或者2147483647(溢出上界)。
 
  
stoi头文件:,c++函数
atoi头文件:,c函数
 
  
 
  
 
  
test:
#include "stdafx.h"
#include 
#include
#include
#include
#include
#include
using namespace std;


int main()
{
	string s1 = "21474839", s2 = "-214748";
	char *s3 = "214748666666663", *s4 = "-21474836488";
	cout << stoi(s1) << endl;
	cout << stoi(s2) << endl;
	cout << atoi(s3) << endl;
	cout << atoi(s4) << endl;
	return 0;
}

你可能感兴趣的:(atoi和stoi)