從百度文庫找的,挺詳細的,跟大家分享一下。
標紅的是我覺得用的比較多,並且大家不太熟悉的。
string(const char *s); //
string(int n,char c); //
此外,
const char &operator[](int n)const;
const char &at(int n)const;
char &operator[](int n);
char &at(int n);
operator[]
int copy(char *s, int n, int pos = 0) const;//
int capacity()const; //
int max_size()const; //
void resize(int len,char c);//
string
string
函數
string &operator=(const string &s);//
string &assign(const char *s);//
string &assign(const char *s,int n);//
string &assign(const string &s);//
string &assign(int n,char c);//
string &assign(const string &s,int start,int n);//
string &assign(const_iterator first,const_itertor last);//
string &append(const char *s); //
string &append(const char *s,int n);//
string &append(const string &s); //
string &append(const string &s,int pos,int n);//
string &append(const_iterator first,const_iterator last);//
運算符
int compare(int pos, int n,const string &s)const;//
int compare(int pos, int n,const string &s,int pos2,int n2)const;//
int compare(const char *s) const;
int compare(int pos, int n,const char *s) const;
int compare(int pos, int n,const char *s, int pos2) const;
compare
int find(const char *s, int pos = 0) const;//
int find(const char *s, int pos, int n) const;//
int rfind(char c, int pos = npos) const;//
int rfind(const char *s, int pos = npos) const;
int rfind(const char *s, int pos, int n = npos) const;
int find_first_of(char c, int pos = 0) const;//
int find_first_of(const char *s, int pos = 0) const;
int find_first_of(const char *s, int pos, int n) const;
int find_first_of(const string &s,int pos = 0) const;
//
int find_first_not_of(char c, int pos = 0) const;
int find_first_not_of(const char *s, int pos = 0) const;
int find_first_not_of(const char *s, int pos,int n) const;
int find_last_of(char c, int pos = npos) const;
int find_last_of(const char *s, int pos = npos) const;
int find_last_of(const char *s, int pos, int n = npos) const;
int find_last_of(const string &s,int pos = npos) const;
int find_last_not_of(char c, int pos = npos) const;
int find_last_not_of(const char *s, int pos = npos) const;
int find_last_not_of(const char *s, int pos, int n) const;
int find_last_not_of(const string &s,int pos = npos) const;
//find_last_of
string &replace(int p0, int n0,const char *s);//
string &replace(int p0, int n0,const char *s, int n);//
string &replace(int p0, int n0,const string &s);//
string &replace(int p0, int n0,const string &s, int pos, int n);//
string &replace(int p0, int n0,int n, char c);//
string &replace(iterator first0, iterator last0,const char *s);//
string &replace(iterator first0, iterator last0,const char *s, int n);//
string &replace(iterator first0, iterator last0,const string &s);//
string &replace(iterator first0, iterator last0,int n, char c);//
string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last);//
string &insert(int p0, const char *s);
string &insert(int p0,const string &s);
string &insert(int p0,const string &s, int pos, int n);
//
string &insert(int p0, int n, char c);//
iterator insert(iterator it, char c);//
void insert(iterator it, const_iterator first, const_iterator last);//
void insert(iterator it, int n, char c);//
iterator erase(iterator it);//
string &erase(int pos = 0, int n = npos);//
string
用
const_iterator begin()const;
iterator begin(); //
const_iterator end()const;
iterator end(); //
const_iterator rbegin()const;
iterator rbegin(); //
const_iterator rend()const;
iterator rend(); //
rbegin
通過定義
例如:
string input("hello,this is a test");
istringstream is(input);
string s1,s2,s3,s4;
is>>s1>>s2>>s3>>s4;//s1="hello,this",s2="is",s3="a",s4="test"
ostringstream os;
os<<s1<<s2<<s3<<s4;
cout<<os.str();