C++中string与int\double等互转

double转为string (int\float等类似)

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include <string> 
#inlcude <sstream>
int main(){
  double   d=123.456; 
  string   str; 
  stringstream   ss; 
  ss<<d; 
  ss>>str;
}

 

string转为double(int\float等类似)

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include <string> 
#inlcude <sstream>
int main(){
  double s;
  string str="123.56";
  stringstream ss;
  ss<<str;//从str输入  
  ss>>s;//输出到double
  ss.clear();
}

 

挂一漏万,C++暂时够用,以后有需要再补充

 

 

from:http://www.cnblogs.com/ziqiao/archive/2010/11/06/1870527.html

你可能感兴趣的:(String)