C++,stringクラス共通関数


stringクラスの構造関数:string(const char*s);//c文字列sでstring(int n,char c)を初期化する.//n文字cで初期化するほか、stringクラスはデフォルトのコンストラクタとstring s 1などのコンストラクタのコピーをサポートします.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&s 2);//現在の文字列とs 2の値の交換
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変数を定義することによって、ヘッダファイルには、例えば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<