c++ STL string

string and an array of similar, but more flexible than arrays. For more examples, see Note 10.3

operating

1) =, s.assign () // assigned to a new value
2) swap () // exchange the contents of two strings
3) + =, s.append () , s.push_back () // add tail character
4) s.insert () // inserting characters
5) s.erase () // delete character
6) s.clear () // delete all characters
7) s.replace (// replacement character)
8) + / / concatenated string
9) ==,! =, < , <=,>,> =, compare () // string comparison
10) size (), length ( ) // returns the number of characters
11) max_size () / / returns the maximum number of characters may
12) s.empty () // determines whether the string is empty
13) s.capacity () // returns the previous character capacity reallocation
14) reserve () // retain a certain amount of memory receiving a number of character
15) [], at () // single character access
16) >>, getline () // read values from a stream
. 17) // << stream seeking to write the value
18) copy () // will be assigned to a certain value C_string
. 19) the c_str () // returns a pointer pointing to content strings regular C (C_string) of this string has the same string '\ 0'
20 is) Data () // will the contents of an array of characters to return no '\ 0'
21) s.substr () // returns a substring
22) begin () end () // provide similar support STL iterators
23) rbegin () rend () // reverse iterator
24) get_allocator () / / return configurator

 

string a;

a [ "abc"] = 1; // also true

 string s3 = "hello"; // s3 is a literal copy of the

string s4 ( "hello"); // equivalent to s3 = "hello"

string s5 (10, 'c'); // s5 content is cccccccccc

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11621572.html