std::stringクラス操作関数の説明

12248 ワード

最近、文字列の解析と組み合わせを振り回して、stringクラスの操作を整理して、これを見るのはライブラリドキュメントを見るよりも目がいいです.
<span style="color:#009900;"><span style="background-color: rgb(255, 255, 255);">// string      :</span></span>
string(const char *s);    <span style="color:#009900;">//  c   s   </span>
string(int n,char c);     <span style="color:#009900;">//  n   c   </span>


<span style="color:#009900;">// string      :</span>
const char &operator[](int n)const;
const char &at(int n)const;
char &operator[](int n);
char &at(int n);
<span style="color:#009900;">// operator[] at()          n      , at        ,       out_of_range  ,     []       。</span>
const char *data()const;	<span style="color:#009900;">//      null   c    </span>
const char *c_str()const;	<span style="color:#009900;">//      null   c   </span>
int copy(char *s, int n, int pos = 0) const; <span style="color:#009900;">//       pos   n       s           ,         </span>

<span style="color:#009900;">// string     :</span>
int capacity()const;                                        <span style="color:#009900;">//       ( string                )</span>
int max_size()const;                                        <span style="color:#009900;">//   string               </span>
int size()const;                                            <span style="color:#009900;">//           </span>
int length()const;                                          <span style="color:#009900;">//           </span>
bool empty()const;                                          <span style="color:#009900;">//          </span>
void resize(int len,char c);                                <span style="color:#009900;">//           len,    c       </span>

<span style="color:#009900;">
// string   :</span>
string &operator=(const string &s);			    <span style="color:#009900;">//     s       </span>
string &assign(const char *s);				    <span style="color:#009900;">//  c     s  </span>
string &assign(const char *s,int n);			    <span style="color:#009900;">//  c   s   n     </span>
string &assign(const string &s);			    <span style="color:#009900;">//     s       </span>
string &assign(int n,char c);				    <span style="color:#009900;">//  n   c        </span>
string &assign(const string &s,int start,int n);	    <span style="color:#009900;">//     s  start   n          </span>
string &assign(const_iterator first,const_itertor last);    <span style="color:#009900;">//  first last             </span>

<span style="color:#009900;">// string   :</span>
string &operator+=(const string &s);			    <span style="color:#009900;">//     s           </span>
string &append(const char *s);                              <span style="color:#009900;">//  c     s          </span>
string &append(const char *s,int n);                        <span style="color:#009900;">//  c     s  n             </span>
string &append(const string &s);                            <span style="color:#009900;">//  operator+=()</span>
string &append(const string &s,int pos,int n);              <span style="color:#009900;">//     s  pos   n              </span>
string &append(int n,char c);                               <span style="color:#009900;">//           n   c</span>
string &append(const_iterator first,const_iterator last);  <span style="color:#009900;"> //     first last                </span>


<span style="color:#009900;">// string   :</span>
bool operator==(const string &s1,const string &s2)const;            <span style="color:#009900;">//               ">","<",">=","<=","!="            ;</span>
int compare(const string &s) const;                                 <span style="color:#009900;">//         s   </span>
int compare(int pos, int n,const string &s)const;                   <span style="color:#009900;">//         pos   n          s   </span>
int compare(int pos, int n,const string &s,int pos2,int n2)const;   <span style="color:#009900;">//         pos   n          s pos2   n2            </span>
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;
<span style="color:#009900;">// compare   >   1,<   -1,==   0  
   
// string   :</span>
string substr(int pos = 0,int n = npos) const;                      <span style="color:#009900;">//   pos   n         </span>

<span style="color:#009900;">// string   :</span>
void swap(string &s2);                                              <span style="color:#009900;">//         s2  </span>


<span style="color:#009900;">// string      :</span>
int find(char c, int pos = 0) const;                                <span style="color:#009900;">//  pos      c         </span>
int find(const char *s, int pos = 0) const;                         <span style="color:#009900;">//  pos       s        </span>
int find(const char *s, int pos, int n) const;                      <span style="color:#009900;">//  pos       s  n           </span>
int find(const string &s, int pos = 0) const;                       <span style="color:#009900;">//  pos       s        
//            ,    string::npos  </span>
int rfind(char c, int pos = npos) const;                            <span style="color:#009900;">//  pos          c        </span>
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;
<span style="color:#009900;">//  pos           s  n                 ,        ,     string::npos  </span>
int find_first_of(char c, int pos = 0) const;                       <span style="color:#009900;">//  pos      c        </span>
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;
<span style="color:#009900;">//  pos            s  n               。      string::npos</span>
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;
<span style="color:#009900;">//              s         ,    string::npos</span>
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;
<span style="color:#009900;">// find_last_of find_last_not_of find_first_of find_first_not_of  ,          </span>


<span style="color:#009900;">// string      :</span>
string &replace(int p0, int n0,const char *s);                                              <span style="color:#009900;">//    p0   n0   ,   p0    s</span>
string &replace(int p0, int n0,const char *s, int n);                                       <span style="color:#009900;">//   p0   n0   ,   p0      s  n   </span>
string &replace(int p0, int n0,const string &s);                                            <span style="color:#009900;">//    p0   n0   ,   p0    s</span>
string &replace(int p0, int n0,const string &s, int pos, int n);                            <span style="color:#009900;">//   p0   n0   ,   p0    s  pos   n   </span>
string &replace(int p0, int n0,int n, char c);                                              <span style="color:#009900;">//   p0   n0   ,   p0   n   c</span>
string &replace(iterator first0, iterator last0,const char *s);                             <span style="color:#009900;">//  [first0,last0)           s</span>
string &replace(iterator first0, iterator last0,const char *s, int n);                      <span style="color:#009900;">//  [first0,last0)        s  n   </span>
string &replace(iterator first0, iterator last0,const string &s);                           <span style="color:#009900;">//  [first0,last0)         s</span>
string &replace(iterator first0, iterator last0,int n, char c);                             <span style="color:#009900;">//  [first0,last0)        n   c</span>
string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last); <span style="color:#009900;">//  [first0,last0)        [first,last)      </span>


<span style="color:#009900;">// string      :</span>
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);
<span style="color:#009900;">//  4    p0       s pos    n   </span>
string &insert(int p0, int n, char c);                              <span style="color:#009900;">//     p0   n   c</span>
iterator insert(iterator it, char c);                               <span style="color:#009900;">//  it     c,           </span>
void insert(iterator it, const_iterator first, const_iterator last);<span style="color:#009900;">//  it   [first,last)     </span>
void insert(iterator it, int n, char c);                            <span style="color:#009900;">//  it   n   c</span>


<span style="color:#009900;">// string       </span>
iterator erase(iterator first, iterator last);      <span style="color:#009900;">//   [first,last)       ,           </span>
iterator erase(iterator it);                        <span style="color:#009900;">//   it     ,           </span>
string &erase(int pos = 0, int n = npos);           <span style="color:#009900;">//   pos   n   ,         </span>

<span style="color:#009900;">// string       :
// string               iterator,               ,       ,        。
//  string::iterator string::const_iterator       ,const_iterator          。        :</span>
const_iterator begin()const;
iterator begin();                   <span style="color:#009900;">//   string     </span>
const_iterator end()const;
iterator end();                     <span style="color:#009900;">//   string            </span>
const_iterator rbegin()const;
iterator rbegin();                 <span style="color:#009900;"> //   string          </span>
const_iterator rend()const;
iterator rend();                    <span style="color:#009900;">//   string          
// rbegin rend           ,       string::reverse_iterator,string::const_reverse_iterator  </span>