[C++] String Processing

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{ 
 string s="ab@c";
 
 //reverse and begin() end()
 reverse(s.begin(),s.end());
 cout<<s<<endl;

 //
 cout<<s.length()<<endl;
 cout<<s.empty()<<endl;
 
 //s.swap(b) swap content with string b
 cout<<(int)s.find('@')<<endl;
 cout<<(int)s.find('9')<<endl;
 
 //substr 
 cout<<s.substr(1,2)<<endl;
 cout<<s.substr(0)<<endl;
 
 //erase(delete nth element)
 cout<<s.erase(s.begin()+n);
 return 0;
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *