格式轉換

1.string  to  int

	string str = "123";
	int iteger = atoi(str.c_str());

  • c_str()函數返回一個指向正規C字符串的指針, 內容與本string串相同.這是爲了與c語言兼容,在c語言中沒有string類型,故必須通過string類對象的成員函數c_str()把string 對象轉換成c中的字符串樣式。
  • 字符串轉換成整型數。ASCII to integer 的縮寫。

2. int to string

        string str;
int n=5;
stringstream ss;    //#include<sstream>
ss<<n;
ss>>str;
cout<<str<<endl;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章