【备忘录】c++ 整形浮点<=>字符串 类型转换

一、C风格字符串


1.<stdlib.h>中的转换函数 
atoi atol atoll
itoa ltoa ultoa lltoa
atof ecvt fcvt gcvt
strtol strtoul strtoll strtod


2.
sprintf  sscanf (功能更强大)


二、std::string


1.标准库转换函数 
(using namespace std;)
to_string
stoi stol stoul stoll stoul
stof stod stold


2.字符串流
#include<sstream>
using namespace std;
int ValueOf(const string &str) 
{
    stringstream ss(str);
    int retn;
    ss>>retn;
    if(!ss) throw exception("转换错误!");
    return retn;
} 

posted @ 2013-07-13 12:38  绝不原创的飞龙  阅读(10)  评论(0编辑  收藏  举报  来源