Member functions of string in C ++

  <span style = "font-size: 14px;">
  
  constructor of string class:
  
  string (const char * s); // initialize
  
  string with c string s (int n, char c); // use n characters c initialization
  
  In addition, the string class also supports the default constructor and copy constructor, such as string s1; string s2 = "hello"; both are correct. When the constructed string is too long to be expressed, it will throw a length_error exception.
  
  String character operations:
  
  const char & operator [] (int n) const;
  
  const char & at (int n) const;
  
  char & operator [] (int n);
  
  char & at (int n);
  
  operator [] and at () both return the position of the nth character in the current string, but the at function provides range checking, and an out_of_range exception will be thrown when the boundary is exceeded. Provide inspection access.
  
  const char * data () const; // Return a non-null terminated C character array
  
  const char * c_str () const; // Return a null terminated C string
  
  int copy (char * s, int n, int pos = 0) const; // Copy the n characters starting with pos in the current string to the character array with s as the starting position, and return the actual number of copies
  
  . Characteristic description of string:
  
  int capacity () const; // Return the current capacity (that is, the number of elements in the string that can be stored without increasing memory)
  
  int max_size () const; // Return the length of the largest string that can be stored in the string object
  
  int size () const; // Return the size of the current string
  
  int length () const; // Return the length of the current string
  
  bool empty () const; // Whether the current string is empty
  
  void resize (int len, char c); // Set the current size of the string to len, and fill the insufficient
  
  input and output operations of the
  
  string class with the character c : the string overload operator operator >> is used for input, and the overload operator operator << is also used for output operations.
  
  The function getline (istream & in, string & s); is used to read the string from the input stream in to s, separated by a newline character '\ n'.
  
  Assignment of
  
  string : string & operator = (const string & s); // Assign the string s to the current string
  
  string & assign (const char * s); // Use the c-type string s to assign
  
  string & assign (const char * s, int n); // The n characters starting with the c string s are assigned
  
  string & assign (const string & s); // The string s is assigned to the current string
  
  string & assign (int n, char c);
  
  string & assign (const string & s, int start, int n); // Assign the n characters from start in string s to the current
  
  stringstring & assign (const_iterator first, const_itertor last); // Iterate first and last The part between the devices is assigned to
  
  the connection of the string string:
  
  string & operator + = (const string & s); // Connect the string s to the end of the current string
  
  string & append (const char * s); // The character of type c The string s is connected to the end of the current string
  
  string & append (const char * s, int n); // The first n characters of the type c string s are connected to the end of the current string
  
  string & append (const string & s); // Same operator + = ()
  
  string & append (const string & s, int pos, int n); // Connect the n characters in the string s starting from pos to the end of the current string
  
  string & append (int n, char c); / / Add n characters at the end of the current string c
  
  string & append (const_iterator first, const_iterator last); // Compare the part between the iterator first and last to the end of the current string String
  
  comparison:
  
  bool operator == (const string & s1,const string & s2) const; // Compare whether two strings are equal
  
  Operator ">", "<", "> =", "<=", "! =" Are overloaded for string comparison;
  
  int compare (const string & s) const; // Compare the current string And s size
  
  int compare (int pos, int n, const string & s) const; // Compare the string of n characters starting from pos and the size of s
  
  int compare (int pos, int n, const string & s, int pos2, int n2) const; // Compare the size of the string consisting of n characters starting with pos and the string consisting of n 2 characters starting with pos2 in s
  
  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 function returns 1 when> and returns-when < 1, == returns
  
  a substring of 0 string:
  
  string substr (int pos = 0, int n = npos) const; // returns a string of n characters beginning with pos
  
  , the exchange of the string :
  
  void swap (string & s2) ;// Swap the current string with the value of s2.
  
  The search function of the string class:
  
  int find (char c, int pos = 0) const; // Find the position of the character c in the current string from pos
  
  int find (const char * s, int pos = 0) const; // Find the position of the string s in the current string from pos
  
  int find (const char * s, int pos, int n) const; // From pos Start to find the position of the first n characters in the string s in the current string
  
  int find (const string & s, int pos = 0) const; // Find the position of the string s in the current string from pos
  
  // When the search is successful Return to the position, fail to return the value of string :: npos
  
  int rfind (char c, int pos = npos) const; // Find the position of character c in the current string from pos from back to
  
  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;
  
  // find from pos onwards The position of the string consisting of the first n characters in the string s in the current string, the position is returned if successful, and the value of string :: npos is returned when it fails
  
  int find_first_of (char c, int pos = 0) const; // From pos Start looking for the first occurrence of the character 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;
  
  // Find the first n characters of s in the current string starting from pos The position of the characters in the array. If the search fails, return 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;
  
  // Find the position of the first character not in the string s from the current string, return 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 and find_last_not_of are similar to find_first_of and find_first_not_of, but they are
  
  the replacement functions for finding the string class from back to front :
  
  string & replace (int p0, int n0, const char * s); Delete n0 characters starting from p0, then insert string s
  
  string & replace (int p0, int n0, const char * s, int n) at p0; // Delete n0 characters starting at p0, then insert characters at p0 The first n characters of
  
  string s string & replace (int p0, int n0, const string & s); // Remove the n0 characters starting from p0, and then insert the string s
  
  string & replace (int p0, int n0, const string at p0 & s, int pos, int n); // Delete the n0 characters starting at p0, then insert the n characters starting at pos in the string s at p0
  
  string & replace (int p0, int n0, int n, char c); // Delete the n0 characters starting with p0, then insert n characters at p0 c
  
  string & replace (iterator first0, iterator last0, const char * s); // Replace the part between [first0, last0) with the string s
  
  string & replace (iterator first0, iterator last0, const char * s, int n); // Replace the part between [first0, last0) with s The first n characters of
  
  string & replace (iterator first0, iterator last0, const string & s); // Replace the part between [first0, last0) with string s
  
  string & replace (iterator first0, iterator last0, int n, char c) ; // Replace the part between [first0, last0) with n characters c
  
  string & replace (iterator first0, iterator last0, const_iterator first, const_iterator last); // Replace the part between [first0, last0) with [
  
  The insertion function of the string class between first and last) :
  
  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);
  
  // The first 4 functions insert the first n characters of
  
  string s starting at pos in the position p0 & insert (int p0, int n, char c); // This function inserts n characters at p0 c
  
  iterator insert (iterator it, char c); // Insert character c at it and return the position of the iterator after insertion
  
  void insert (iterator it, const_iterator first, const_iterator last); // Insert characters between [first, last) at it
  
  void insert (iterator it, int n, char c); // Insert n characters at it c
  
  string delete function
  
  iterator erase (iterator first, iterator last); // delete all characters between [first, last), return the position of the
  
  iterator after deletion iterator erase (iterator it); // delete it pointed Characters, return the position of the iterator after deletion
  
  string & erase (int pos = 0, int n = npos); // Delete the n characters starting with pos, and return
  
  the iterator processing of the modified string string class:
  
  The string class provides an iterator iterator that traverses forward and backward. The iterator provides a syntax for accessing individual characters. Similar to pointer operations, the iterator does not check the scope.
  
  Use string :: iterator or string :: const_iterator to declare iterator variables. Const_iterator does not allow you to change the contents of the iterator. Common iterator functions are:
  
  const_iterator begin () const;
  
  iterator begin (); // Return the start position of
  
  stringconst_iterator end () const;
  
  iterator end (); // Return the position after the last character of
  
  stringconst_iterator rbegin ( ) const;
  
  iterator rbegin (); // return the position of the last character of the string
  
  const_iterator rend () const;
  
  iterator rend (); // return the front of the first character position of the string
  
  rbegin and rend are used from back to forward Iterative access, by setting iterator string :: reverse_iterator, string :: const_reverse_iterator to achieve
  
  string stream processing:
  
  by defining the ostringstream and istringstream variables, <sstream> header file
  
  For example:
  
  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();
  
  </span>

 

 

 

https://www.cnblogs.com/zhenhua1618/category/1733914.html
https://www.cnblogs.com/zhenhua1618/category/1733916.html
https://www.cnblogs.com/zhenhua1618/category/1733919.html
https://www.cnblogs.com/zhenhua1618/category/1733920.html
https://www.cnblogs.com/zhenhua1618/category/1733922.html
https://www.cnblogs.com/zhenhua1618/category/1733925.html
https://www.cnblogs.com/zhenhua1618/category/1733927.html
https://www.cnblogs.com/zhenhua1618/category/1733930.html
https://www.cnblogs.com/zhenhua1618/category/1733931.html
https://www.cnblogs.com/zhenhua1618/category/1733933.html
https://www.cnblogs.com/zhenhua1618/category/1733936.html
https://www.cnblogs.com/zhenhua1618/category/1733938.html
https://www.cnblogs.com/zhenhua1618/category/1733940.html
https://www.cnblogs.com/zhenhua1618/category/1733942.html
https://www.cnblogs.com/zhenhua1618/category/1733944.html
https://www.cnblogs.com/zhenhua1618/category/1733947.html
https://www.cnblogs.com/zhenhua1618/category/1733949.html
https://www.cnblogs.com/zhenhua1618/category/1733952.html
https://www.cnblogs.com/zhenhua1618/category/1733954.html
https://www.cnblogs.com/zhenhua1618/category/1733956.html
https://www.cnblogs.com/zhenhua1618/category/1733958.html
https://www.cnblogs.com/zhenhua1618/category/1733960.html
https://www.cnblogs.com/zhenhua1618/category/1733963.html
https://www.cnblogs.com/zhenhua1618/category/1733964.html
https://www.cnblogs.com/zhenhua1618/category/1733965.html
https://www.cnblogs.com/zhenhua1618/category/1733967.html
https://www.cnblogs.com/zhenhua1618/category/1733968.html
https://www.cnblogs.com/zhenhua1618/category/1733970.html
https://www.cnblogs.com/zhenhua1618/category/1733971.html
https://www.cnblogs.com/zhenhua1618/category/1733972.html
https://www.cnblogs.com/zhenhua1618/category/1733974.html
https://www.cnblogs.com/zhenhua1618/category/1733975.html
https://www.cnblogs.com/zhenhua1618/category/1733976.html
https://www.cnblogs.com/zhenhua1618/category/1733978.html
https://www.cnblogs.com/zhenhua1618/category/1733979.html
https://www.cnblogs.com/zhenhua1618/category/1733980.html
https://www.cnblogs.com/zhenhua1618/category/1733982.html
https://www.cnblogs.com/zhenhua1618/category/1733983.html
https://www.cnblogs.com/zhenhua1618/category/1733985.html
https://www.cnblogs.com/zhenhua1618/category/1733986.html
https://www.cnblogs.com/zhenhua1618/category/1733987.html
https://www.cnblogs.com/zhenhua1618/category/1733989.html
https://www.cnblogs.com/zhenhua1618/category/1733990.html
https://www.cnblogs.com/zhenhua1618/category/1733992.html
https://www.cnblogs.com/zhenhua1618/category/1733993.html
https://www.cnblogs.com/zhenhua1618/category/1733994.html
https://www.cnblogs.com/zhenhua1618/category/1733996.html
https://www.cnblogs.com/zhenhua1618/category/1733997.html
https://www.cnblogs.com/zhenhua1618/category/1733998.html
https://www.cnblogs.com/zhenhua1618/category/1734001.html
https://www.cnblogs.com/zhenhua1618/category/1734002.html
https://www.cnblogs.com/zhenhua1618/category/1734004.html
https://www.cnblogs.com/zhenhua1618/category/1734005.html
https://www.cnblogs.com/zhenhua1618/category/1734006.html
https://www.cnblogs.com/zhenhua1618/category/1734008.html
https://www.cnblogs.com/zhenhua1618/category/1734009.html
https://www.cnblogs.com/zhenhua1618/category/1734010.html
https://www.cnblogs.com/zhenhua1618/category/1734012.html
https://www.cnblogs.com/zhenhua1618/category/1734013.html
https://www.cnblogs.com/zhenhua1618/category/1734015.html
https://www.cnblogs.com/zhenhua1618/category/1734016.html
https://www.cnblogs.com/zhenhua1618/category/1734017.html
https://www.cnblogs.com/zhenhua1618/category/1734019.html
https://www.cnblogs.com/zhenhua1618/category/1734020.html
https://www.cnblogs.com/zhenhua1618/category/1734021.html
https://www.cnblogs.com/zhenhua1618/category/1734023.html
https://www.cnblogs.com/zhenhua1618/category/1734024.html
https://www.cnblogs.com/zhenhua1618/category/1734027.html
https://www.cnblogs.com/zhenhua1618/category/1734028.html
https://www.cnblogs.com/zhenhua1618/category/1734030.html
https://www.cnblogs.com/zhenhua1618/category/1734032.html
https://www.cnblogs.com/zhenhua1618/category/1734033.html
https://www.cnblogs.com/zhenhua1618/category/1734034.html
https://www.cnblogs.com/zhenhua1618/category/1734036.html
https://www.cnblogs.com/zhenhua1618/category/1734037.html
https://www.cnblogs.com/zhenhua1618/category/1734039.html
https://www.cnblogs.com/zhenhua1618/category/1734041.html
https://www.cnblogs.com/zhenhua1618/category/1734042.html
https://www.cnblogs.com/zhenhua1618/category/1734044.html
https://www.cnblogs.com/zhenhua1618/category/1734045.html
https://www.cnblogs.com/zhenhua1618/category/1734046.html
https://www.cnblogs.com/zhenhua1618/category/1734048.html
https://www.cnblogs.com/zhenhua1618/category/1734049.html
https://www.cnblogs.com/zhenhua1618/category/1734051.html
https://www.cnblogs.com/zhenhua1618/category/1734052.html
https://www.cnblogs.com/zhenhua1618/category/1734053.html
https://www.cnblogs.com/zhenhua1618/category/1734055.html
https://www.cnblogs.com/zhenhua1618/category/1734056.html
https://www.cnblogs.com/zhenhua1618/category/1734057.html
https://www.cnblogs.com/zhenhua1618/category/1734059.html
https://www.cnblogs.com/zhenhua1618/category/1734060.html
https://www.cnblogs.com/zhenhua1618/category/1734062.html
https://www.cnblogs.com/zhenhua1618/category/1734063.html
https://www.cnblogs.com/zhenhua1618/category/1734064.html
https://www.cnblogs.com/zhenhua1618/category/1734066.html
https://www.cnblogs.com/zhenhua1618/category/1734067.html
https://www.cnblogs.com/zhenhua1618/category/1734069.html
https://www.cnblogs.com/zhenhua1618/category/1734070.html
https://www.cnblogs.com/zhenhua1618/category/1734071.html
https://www.cnblogs.com/zhenhua1618/category/1734073.html
https://www.cnblogs.com/zhenhua1618/category/1734074.html
https://www.cnblogs.com/zhenhua1618/category/1734075.html
https://www.cnblogs.com/zhenhua1618/category/1734077.html
https://www.cnblogs.com/zhenhua1618/category/1734078.html
https://www.cnblogs.com/zhenhua1618/category/1734080.html
https://www.cnblogs.com/zhenhua1618/category/1734081.html
https://www.cnblogs.com/zhenhua1618/category/1734082.html
https://www.cnblogs.com/zhenhua1618/category/1734084.html
https://www.cnblogs.com/zhenhua1618/category/1734085.html
https://www.cnblogs.com/zhenhua1618/category/1734086.html
https://www.cnblogs.com/zhenhua1618/category/1734087.html
https://www.cnblogs.com/zhenhua1618/category/1734088.html
https://www.cnblogs.com/zhenhua1618/category/1734090.html
https://www.cnblogs.com/zhenhua1618/category/1734091.html
https://www.cnblogs.com/zhenhua1618/category/1734092.html
https://www.cnblogs.com/zhenhua1618/category/1734094.html
https://www.cnblogs.com/zhenhua1618/category/1734095.html
https://www.cnblogs.com/zhenhua1618/category/1734097.html
https://www.cnblogs.com/zhenhua1618/category/1734098.html
https://www.cnblogs.com/zhenhua1618/category/1734099.html
https://www.cnblogs.com/zhenhua1618/category/1734101.html
https://www.cnblogs.com/zhenhua1618/category/1734102.html
https://www.cnblogs.com/zhenhua1618/category/1734103.html
https://www.cnblogs.com/zhenhua1618/category/1734105.html
https://www.cnblogs.com/zhenhua1618/category/1734106.html
https://www.cnblogs.com/zhenhua1618/category/1734108.html
https://www.cnblogs.com/zhenhua1618/category/1734109.html
https://www.cnblogs.com/zhenhua1618/category/1734110.html
https://www.cnblogs.com/zhenhua1618/category/1734112.html
https://www.cnblogs.com/zhenhua1618/category/1734113.html
https://www.cnblogs.com/zhenhua1618/category/1734115.html
https://www.cnblogs.com/zhenhua1618/category/1734116.html
https://www.cnblogs.com/zhenhua1618/category/1734117.html
https://www.cnblogs.com/zhenhua1618/category/1734119.html
https://www.cnblogs.com/zhenhua1618/category/1734120.html
https://www.cnblogs.com/zhenhua1618/category/1734121.html
https://www.cnblogs.com/zhenhua1618/category/1734123.html
https://www.cnblogs.com/zhenhua1618/category/1734124.html
https://www.cnblogs.com/zhenhua1618/category/1734126.html
https://www.cnblogs.com/zhenhua1618/category/1734127.html
https://www.cnblogs.com/zhenhua1618/category/1734128.html
https://www.cnblogs.com/zhenhua1618/category/1734130.html
https://www.cnblogs.com/zhenhua1618/category/1734131.html
https://www.cnblogs.com/zhenhua1618/category/1734133.html
https://www.cnblogs.com/zhenhua1618/category/1734134.html
https://www.cnblogs.com/zhenhua1618/category/1734135.html
https://www.cnblogs.com/zhenhua1618/category/1734137.html
https://www.cnblogs.com/zhenhua1618/category/1734138.html
https://www.cnblogs.com/zhenhua1618/category/1734139.html
https://www.cnblogs.com/zhenhua1618/category/1734141.html
https://www.cnblogs.com/zhenhua1618/category/1734142.html
https://www.cnblogs.com/zhenhua1618/category/1734144.html
https://www.cnblogs.com/zhenhua1618/category/1734145.html
https://www.cnblogs.com/zhenhua1618/category/1734146.html
https://www.cnblogs.com/zhenhua1618/category/1734148.html
https://www.cnblogs.com/zhenhua1618/category/1734149.html
https://www.cnblogs.com/zhenhua1618/category/1734151.html
https://www.cnblogs.com/zhenhua1618/category/1734152.html
https://www.cnblogs.com/zhenhua1618/category/1734153.html
https://www.cnblogs.com/zhenhua1618/category/1734155.html
https://www.cnblogs.com/zhenhua1618/category/1734156.html
https://www.cnblogs.com/zhenhua1618/category/1734158.html
https://www.cnblogs.com/zhenhua1618/category/1734159.html
https://www.cnblogs.com/zhenhua1618/category/1734160.html
https://www.cnblogs.com/zhenhua1618/category/1734162.html
https://www.cnblogs.com/zhenhua1618/category/1734163.html
https://www.cnblogs.com/zhenhua1618/category/1734165.html
https://www.cnblogs.com/zhenhua1618/category/1734166.html
https://www.cnblogs.com/zhenhua1618/category/1734167.html
https://www.cnblogs.com/zhenhua1618/category/1734169.html
https://www.cnblogs.com/zhenhua1618/category/1734170.html
https://www.cnblogs.com/zhenhua1618/category/1734172.html
https://www.cnblogs.com/zhenhua1618/category/1734173.html
https://www.cnblogs.com/zhenhua1618/category/1734174.html
https://www.cnblogs.com/zhenhua1618/category/1734176.html
https://www.cnblogs.com/zhenhua1618/category/1734177.html
https://www.cnblogs.com/zhenhua1618/category/1734178.html
https://www.cnblogs.com/zhenhua1618/category/1734180.html
https://www.cnblogs.com/zhenhua1618/category/1734181.html
https://www.cnblogs.com/zhenhua1618/category/1734183.html
https://www.cnblogs.com/zhenhua1618/category/1734184.html
https://www.cnblogs.com/zhenhua1618/category/1734185.html
https://www.cnblogs.com/zhenhua1618/category/1734187.html
https://www.cnblogs.com/zhenhua1618/category/1734188.html
https://www.cnblogs.com/zhenhua1618/category/1734190.html
https://www.cnblogs.com/zhenhua1618/category/1734191.html
https://www.cnblogs.com/zhenhua1618/category/1734192.html
https://www.cnblogs.com/zhenhua1618/category/1734194.html
https://www.cnblogs.com/zhenhua1618/category/1734195.html

Guess you like

Origin www.cnblogs.com/zhenhua1618/p/12729566.html