STL--string
28467 ワード
string :
string(const char *s); // c s
string(int n,char c); // n c
,string , string s1;string s2="hello"; 。 string length_error
string :
const char &operator[](int n)const;
const char &at(int n)const;
char &operator[](int n);
char &at(int n);
operator[] at() n , at , out_of_range , [] 。
const char *data()const;// null c
const char *c_str()const;// null c
int copy(char *s, int n, int pos = 0) const;// pos n s ,
string :
int capacity()const; // ( string )
int max_size()const; // string
int size()const; //
int length()const; //
bool empty()const; //
void resize(int len,char c);// len, c
string :
string operator>> , operator<< 。
getline(istream &in,string &s); in s , '
' 。
string :
string &operator=(const string &s);// s
string &assign(const char *s);// c s
string &assign(const char *s,int n);// c s n
string &assign(const string &s);// s
string &assign(int n,char c);// n c
string &assign(const string &s,int start,int n);// s start n
string &assign(const_iterator first,const_itertor last);// first last
string :
string &operator+=(const string &s);// s
string &append(const char *s); // c s
string &append(const char *s,int n);// c s n
string &append(const string &s); // operator+=()
string &append(const string &s,int pos,int n);// s pos n
string &append(int n,char c); // n c
string &append(const_iterator first,const_iterator last);// first last
string :
bool operator==(const string &s1,const string &s2)const;//
">","<",">=","<=","!=" ;
int compare(const string &s) const;// s
int compare(int pos, int n,const string &s)const;// pos n s
int compare(int pos, int n,const string &s,int pos2,int n2)const;// pos n s pos2 n2
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 > 1,< -1,== 0
string :
string substr(int pos = 0,int n = npos) const;// pos n
string :
void swap(string &s2); // s2
string :
int find(char c, int pos = 0) const;// pos c
int find(const char *s, int pos = 0) const;// pos s
int find(const char *s, int pos, int n) const;// pos s n
int find(const string &s, int pos = 0) const;// pos s
// , string::npos
int rfind(char c, int pos = npos) const;// pos c
int rfind(const char *s, int pos = npos) const;
int rfind(const char *s, int pos, int n = npos) const;
int rfind(const string &s,int pos = npos) const;
// pos s n , , string::npos
int find_first_of(char c, int pos = 0) const;// pos c
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;
// pos s n 。 string::npos
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_first_not_of(const string &s,int pos = 0) const;
// s , string::npos
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 find_last_not_of find_first_of find_first_not_of ,
string :
string &replace(int p0, int n0,const char *s);// p0 n0 , p0 s
string &replace(int p0, int n0,const char *s, int n);// p0 n0 , p0 s n
string &replace(int p0, int n0,const string &s);// p0 n0 , p0 s
string &replace(int p0, int n0,const string &s, int pos, int n);// p0 n0 , p0 s pos n
string &replace(int p0, int n0,int n, char c);// p0 n0 , p0 n c
string &replace(iterator first0, iterator last0,const char *s);// [first0,last0) s
string &replace(iterator first0, iterator last0,const char *s, int n);// [first0,last0) s n
string &replace(iterator first0, iterator last0,const string &s);// [first0,last0) s
string &replace(iterator first0, iterator last0,int n, char c);// [first0,last0) n c
string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last);// [first0,last0) [first,last)
string :
string &insert(int p0, const char *s);
string &insert(int p0, const char *s, int n);
string &insert(int p0,const string &s);
string &insert(int p0,const string &s, int pos, int n);
// 4 p0 s pos n
string &insert(int p0, int n, char c);// p0 n c
iterator insert(iterator it, char c);// it c,
void insert(iterator it, const_iterator first, const_iterator last);// it [first,last)
void insert(iterator it, int n, char c);// it n c
string
iterator erase(iterator first, iterator last);// [first,last) ,
iterator erase(iterator it);// it ,
string &erase(int pos = 0, int n = npos);// pos n ,
string :
string iterator, , , 。
string::iterator string::const_iterator ,const_iterator 。 :
const_iterator begin()const;
iterator begin(); // string
const_iterator end()const;
iterator end(); // string
const_iterator rbegin()const;
iterator rbegin(); // string
const_iterator rend()const;
iterator rend(); // string
rbegin rend , string::reverse_iterator,string::const_reverse_iterator
:
ostringstream istringstream ,<sstream>
:
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();
変換元:http://www.cnblogs.com/wangkangluo1/archive/2011/07/22/2114118.html