All functions and functions of the String class of C + +

Source: Internet
Author: User
Tags int size
Turn from: http://chaozaiai.blog.163.com/blog/static/91328155201223181041376/


The Append function can add a string (or data string) to the back of a string
The Assign function can set the contents of a string (or data string) to a string
The AT function can return characters at a location in a string
The BEGIN function will return the starting locator of the string
The C_STR function can output the contents of a string object in the form of a C-language string
The capacity function can return the size of the object container currently in control
The Compare function will return the controllable character Fulu capacity
The copy function copies the contents of the data string into a single data string
The data function can pass the first start pointer of a string
Empty function can determine whether a data string is an empty string
The End function will return the Terminator locator for the string
The erase function clears the data in the container
The Find function can look in the container for the location of the data that matches the request.
The find_first_of function can look in the container for the first occurrence of the data that meets the specific requirements
The find_first_not_of function can look in the container for the first occurrence of data that does not meet specific requirements
The find_last_of function can look in the container for the last occurrence of the data that meets a particular requirement.
The find_last_not_of function can look in the container for the last occurrence of data that does not meet a particular requirement
The Insert function inserts data into a specific location in the container
The length function can compute the lengths of the data string
The Replace function can insert data into a specific location in a container
The reserve function can guarantee the return value of the capacity function, must be greater than a certain number
Resize function can determine the return value of the size function, must be greater than a certain number
The RFind function can look in the container for the last occurrence of the data that meets a particular requirement.
The size function can return the current object container sizes
The SUBSTR function can reduce the string to fewer strings
The swap function can exchange two of strings of content
The Max_size function can exchange two of strings of content
The Getline function can store input data into a container through an input device
The swap function can exchange the contents of two data strings


String functions
Str... String operating system Functions String.h
strcat add a string to another string (merge)
STRCHR the first occurrence of a given character in a scan string (search)
STRCMP compares a string to another string (comparison)
The first segment of a STRCSPN scan string that does not contain a given string collection character (comparison)
StrDup copy string to a newly created location (copy)
STRICMP compares a string to another string, regardless of case (comparison)
Strcmpi compares a string to another string, regardless of case (comparison)
Strlen compute the length of the string (search)
Uppercase letters in the STRLWR conversion string are lowercase (modified)
Strncat to add a portion of a string to another string (merge)
strncmp a portion of a string compared to a portion of another string (comparison)
strncpy the given number of bytes in a copy string to another string, truncated or filled (copy) if necessary
Strncmpi compares a portion of a string with a portion of another string, regardless of case (comparison)
Strnset sets the specified number of bytes in the string to the given character (modify)
STRPBRK Scan for the first occurrence of any character on a string in a given set (search)
STRCHR scan for the last occurrence of a given character in a string (search)
Strrev Reverse sequence (modification)
Strset sets all characters in the string to the given character (modified)
STRSPN scans for the first occurrence of a subset of a given set of characters in a string (search)
STRSTR Scan the occurrence of a given substring in a string (search)
Strtod converts a string to a double value (conversion)
Strtok search for a word in a string separated by the symbols defined in the second string (search)
Strtol converts a string to a long integer value (conversion)
STRUPR converts all lowercase letters in a string to uppercase (modified)


Turn from: http://hi.baidu.com/shazi129/item/d24699affd671916a8cfb788
Constructor of String class:
String (const char *s); Class with C string S.
string (int N,char c); Class with N-character C
In addition, the string class also supports default constructors and copy constructors, such as String s1;string s2= "Hello," which is the correct notation. Length_error exception is thrown when the constructed string is too long to be expressed


Character operations for string classes:
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 a range check and throws a Out_of_range exception when the bounds are crossed, and the subscript operator [] does not provide check access.
const char *data () const;//returns a non-null terminated array of C characters
const char *C_STR () const;//returns a null-terminated C string
int copy (char *s, int n, int pos = 0) const;//copies n characters in the current string starting with Pos to an array of characters starting with S, returning the number of actual copies


Description of the attribute of string:
int capacity () const; Returns the current capacity (that is, the number of elements in string that do not need to increase memory)
int max_size () const; Returns the length of the largest string that can be stored in a string object
int size () const; Returns the size of the current string
int length () const; Returns 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 in the insufficient part with character C
Input and output operations for the string class:
The string class overload operator operator>> is used for input, and the same overloaded operator operator<< is used for output operations.
function Getline (IStream &in,string &s), which is used to read a string from 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);//Assign value with C type string s
String &assign (const char *s,int n);//n-word assignments value starting with C string s
String &assign (const string &s);//Assign the string s to the current string
String &assign (int n,char c);//Assign value to the current string with n characters c
String &assign (const string &s,int start,int N);/to assignments the current string with n words from start in the string s
String &assign (Const_iterator first,const_itertor last);//Assign the part between the primary and last iterators to the string


String's connection:
String &operator+= (const string &s);//Connect the string s to the end of the current string
String &append (const char *s); Connect the C type string s to the end of the current string
String &append (const char *s,int n);//The first n words of the C type string s are fonts to the end of the current string
String &append (const string &s); With operator+= ()
String &append (const string &s,int pos,int N) fonts to the end of the current string with n words starting from POS in string s
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);//Connect the portion of the iterator between the primary and last to the end of the current string


Comparison of String:
BOOL operator== (const string &s1,const string &s2) const;//compare two strings for equality
Operators ">", "<", ">=", "<=", "!=" are overloaded for string comparisons;
int compare (const string &s) const;//compares the current string and the size of s
int compare (int pos, int n,const string &s) const;//Compare the current string of n characters from Pos to the size of s
int compare (int pos, int n,const string &s,int pos2,int n2) const;// Compares the size of a string of n characters from the current string beginning with a POS to a N2 character that starts 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 0 when 1,< returns -1,== at >
Substring of string:
String substr (int pos = 0,int n = NPOs) const;//return of N-character strings starting with Pos
Exchange of String:
void Swap (string &s2); Swap the value of the current string and S2


Lookup function for String class:
int find (char c, int pos = 0) const;//Look for the character C at the position of the current string from the POS
int find (const char *s, int pos = 0) const;//The position of the string s in the current string starting from Pos
int find (const char *s, int pos, int n) const;//The position of the first n characters in the string s in the current string starting from the POS
int find (const string &s, int pos = 0) const;//The position of the string s in the current string starting from Pos
Returns the location of the String::npos when the lookup succeeds, and the failure returns the value of the
int RFind (char c, int pos = NPOs) const;//Find the position of the character C in the current string from the beginning of the POS
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;
From the beginning of the POS find the position of the first n characters in the string s in the current string, successfully return to the position, and return the value of String::npos when the failure occurs
int find_first_of (char c, int pos = 0) const;//Find the first occurrence of character C from Pos
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;
Starts from the POS to find the position of the first character in the current string in an array of the top n characters of S. Lookup failed 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;
Finds the first occurrence of a character that is not in string s from the current string, and fails back to 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, just looking forward from the back


substitution function for String class:
String &replace (int p0, int n0,const char *s)//delete p0 characters starting from N0, then insert string s at P0
String &replace (int p0, int n0,const char *s, int n);//delete p0 characters that are starting with the, and then insert the first n characters of the string s at N0
String &replace (int p0, int n0,const string &s)//delete p0 characters starting from N0, then insert string s at P0
String &replace (int p0, int n0,const string &s, int pos, int n);//delete p0 start n0 characters, then insert n characters from Pos in string s at P0
String &replace (int p0, int n0,int n, char c);//delete n0 characters starting p0, then insert n characters at P0
String &replace (iterator first0, iterator last0,const char *s);//replace the portion 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 the first n characters of S
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 portion between [first0,last0) with n characters c
String &replace (iterator first0, iterator last0,const_iterator-I, const_iterator last);//Put [First0, LAST0) is replaced by a string between [First,last]


Insert function for String class:
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 the POS in the string s at the P0 position
String &insert (int p0, int n, char c);//This function inserts n characters c at p0
Iterator insert (iterator it, char c);//insert character C at it to return the position of the inserted post iterator
void Insert (iterator it, Const_iterator, const_iterator last);//insert characters between [first,last] at it
void Insert (iterator it, int n, char c);//insert n characters C at it


Delete function for String class
Iterator Erase (iterator primary, iterator last);//delete all characters between [First,last], return the position of the post-deletion iterator
Iterator Erase (iterator it); Remove the character that it points to, and return the position of the post-deletion iterator
String &erase (int pos = 0, int n = npos);//delete the N-character at the beginning of the POS, return the modified string


Iterator processing for string classes:
The string class provides iterator iterator for forward and backward traversal, which provides the syntax to access individual characters, similar to pointer operations, without the iterator checking the scope.
Declaring an iterator variable with string::iterator or String::const_iterator, Const_iterator does not allow changes to the contents of the iteration. Common iterator functions are:
Const_iterator begin () const;
Iterator begin (); Returns the starting position of a string
Const_iterator end () const;
Iterator End (); Returns the position after the last character of a string
Const_iterator rbegin () const;
Iterator Rbegin (); Returns the position of the last character of a string
Const_iterator rend () const;
Iterator rend (); Returns the front of the first character position of a string
Rbegin and rend are used for iterative access from backward forward, by setting the iterator String::reverse_iterator,string::const_reverse_iterator implementation


String Stream Processing:
Implementing the,<sstream> header file by defining the Ostringstream and Istringstream variables
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 ();
Host Comment: Very good, very powerful! However, the original site of the reprint was forgotten.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.