String

取出string裏的一部分

string string::substr(index,length);

string s = "hello world!";
string str = s.substr(6,5);
cout<<str<<endl;
//str = "world"

將string轉化成int

int atoi(string.c_str());

string s = "123";
int a = atoi(s.c_str());
cout<<a<<endl;
// a = 123

string ss = "01234";
itn b = atoi(ss.c_str());
cout<<b<<endl;
// b = 1234 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章