Carlward blog

统计

留言簿

阅读排行榜

评论排行榜

std:string 与其它基本数据类型的转换

string -> char*

std::string str("12345");

char *pChar = NULL;

pChar = std::string.c_str();

char* -> string

char* pChar = new char[10];

std::string str;

str = pChar;

string -> double

std::string str("12345");

double n;

n = atof(str.c_str());

int -> string

int i = 0;

char TempChar[100];

sprintf(TempChar, "int %d to string", i);

std::string Str(TempChar);

posted on 2009-11-29 01:16 Carlward 阅读(332) 评论(0)  编辑 收藏 引用 所属分类: STL