C++中怎么把字符串string型的数字转换成整型int型的数字?

日期:2016-05-19 16:49:37 人气:1

C++中怎么把字符串string型的数字转换成整型int型的数字?

有一定C++基础的人不难写出字符串到整数的转换代码 如果是初学者,考虑使用atoi函数(包含stdlib.h或者cstdlib函数,事实上,包含iostream就够了) 原型: int atoi(const char *str); 用法: std::string str="789";int num=atoi(str.c_str());std::cout<<num;或者: char str[]="789";int num=atoi(str);std::
    A+
热门评论