64,633
社区成员
发帖
与我相关
我的任务
分享
char *cp="Stately plump Buck";
1、
string& assign ( const string& str );
string& assign ( const string&, size_t pos, size_t n );
string& assign ( const char* s, size_t n );
string& assign ( const char* s );
string& assign ( size_t n, char c );
template <class InputIterator>
string& assign ( InputIterator first, InputIterator last );
Assign content to string
Assigns new content to the string replacing its current content.
The arguments passed to the function determine the new content:
string& assign ( const string& str );
Sets a copy of str as the new content.
string& assign ( const string& str, size_t pos, size_t n );
Sets a copy of a substring of str as the new content. The substring is the portion of str that begins at the character position pos and takes up to n characters (it takes less than n if the end of str is reached before).
string& assign ( const char * s, size_t n );
Sets as the new content a copy of the string formed by the first n characters of the array pointed by s.
string& assign ( const char * s );
Sets a copy of the string formed by the null-terminated character sequence (C string) pointed by s as the new content. The length of the caracter sequence is determined by the first ocurrence of a null character (as determined by traits.length(s)).
string& assign ( size_t n, char c );
Sets a string formed by a repetition of character c, n times, as the new content.
template<class InputIterator> string& assign (InputIterator first, InputIterator last);
If InputIterator is an integral type, behaves as the previous member function version, effectively setting as the new content
a string formed by the repetition first times of the character equivalent to last.
In any other case, the content is set to the values of the elements that go from element referred to by iterator first to the
element right before the one referred to by iterator last.
2、
size_t find ( const string& str, size_t pos = 0 ) const;
size_t find ( const char* s, size_t pos, size_t n ) const;
size_t find ( const char* s, size_t pos = 0 ) const;
size_t find ( char c, size_t pos = 0 ) const;
Find content in string
Searches the string for the content specified in either str, s or c, and returns the position of the first occurrence in the string.
When pos is specified the search only includes characters on or after position pos, ignoring any possible occurrences in previous locations.
Notice that unlike member find_first_of, whenever more than one character is being searched for, it is not enough that only one of these characters match, but the entire sequence of characters to find must be matched.
Parameters
str
string to be searched for in the object. The entire content of str must be matched in some part of the string to be considered a match.
s
Array with a sequence of characters.
In the second member function version, the size of the content to be matched is only determined by parameter n.
In the third version, a null-terminated sequence is expected, and its end is determined by the first occurrence of a null character in it.
n
Length of sequence of characters to search for.
c
Individual character to be searched for.
pos
Position of the first character in the string to be taken into consideration for possible matches. A value of 0 means that the entire string is considered.
Return Value
The position of the first occurrence in the string of the searched content.
If the content is not found, the member value npos is returned.