📄 bas_0007.htm
字号:
basic_string&
<B>append</B> (const charT* s);
basic_string&
<B>append</B> (size_type n, charT c );
template<class InputIterator>
basic_string&
<B>append</B> (InputIterator first, InputIterator last);</PRE>
<UL><P>Append another string to the end of this string. The first two functions append the lesser of <SAMP>n</SAMP> and <SAMP>s.size() - pos</SAMP> characters of <SAMP>s</SAMP>, beginning at position <SAMP>pos</SAMP> to this string. The second member will throw an <SAMP>out_of_range</SAMP> exception if <SAMP>pos > str.size()</SAMP>. The third member appends <SAMP>n</SAMP> characters of the array pointed to by <SAMP>s</SAMP>. The fourth variation appends elements from the array pointed to by <SAMP>s</SAMP> up to, but not including, a <SAMP>traits::eos()</SAMP> character. The fifth variation appends <SAMP>n</SAMP> repetitions of <SAMP>c</SAMP>. The final <SAMP>append</SAMP> function appends the elements specified in the range <SAMP>[first, last)</SAMP>. </P>
<P>All functions will throw a <SAMP>length_error</SAMP> exception if the resulting length will exceed <SAMP>max_size()</SAMP>. All return a reference to this string after completion.</P>
</UL>
<PRE>basic_string&
<B>assign </B>(const basic_string& s);
basic_string&
<B>assign</B> (const basic_string& s,
size_type pos, size_type n);
basic_string&
<B>assign</B> (const charT* s, size_type n);
basic_string&
<B>assign</B> (const charT* s);
basic_string&
<B>assign</B> (size_type n, charT c );
template<class InputIterator>
basic_string&
<B>assign</B> (InputIterator first, InputIterator last);
</PRE>
<UL><P>Replace the value of this string with the value of another. </P>
<P>All versions of the function assign values to this string. The first two variations assign the lesser of <SAMP>n</SAMP> and <SAMP>s.size() - pos </SAMP>characters of <SAMP>s</SAMP>, beginning at position <SAMP>pos</SAMP>. The second variation throws an <SAMP>out_of_range</SAMP> exception if <SAMP>pos > str.size()</SAMP>. The third version of the function assigns <SAMP>n</SAMP> characters of the array pointed to by <SAMP>s</SAMP>. The fourth version assigns elements from the array pointed to by <SAMP>s</SAMP> up to, but not including, a <SAMP>traits::eos()</SAMP> character. The fifth assigns one or <SAMP>n</SAMP> repetitions of <SAMP>c</SAMP>. The last variation assigns the members specified by the range <SAMP>[first, last)</SAMP>. </P>
<P>All functions will throw a <SAMP>length_error</SAMP> exception if the resulting length will exceed <SAMP>max_size()</SAMP>. All return a reference to this string after completion.</P>
</UL>
<PRE>const_reference
<B>at</B> (size_type pos) const;
reference
<B>at</B> (size_type pos);</PRE>
<UL><P>If <SAMP>pos < size()</SAMP>, returns the element at position <SAMP>pos</SAMP> in this string. Otherwise, an <SAMP>out_of_range</SAMP> exception is thrown.</P>
</UL>
<PRE>size_type
<B>capacity</B> () const;</PRE>
<UL><P>Returns the current storage capacity of the string. This is guaranteed to be at least as large as <SAMP>size()</SAMP>.</P>
</UL>
<PRE>int
<B>compare</B> (const basic_string& str);</PRE>
<UL><P>Returns the result of a lexographical comparison between elements of this string and elements of <SAMP>str</SAMP>. The return value is: </P>
<PRE><0 if size() < str.size()</PRE>
<PRE>0 if size() == str.size()
>0 if size() > str.size()
</PRE></UL>
<PRE>int
<B>compare</B> (size_type pos1, size_type n1,
const basic_string& str) const;
int
<B>compare</B> (size_type pos1, size_type n1, const basic_string& str,
size_type pos2, size_type n2) const;
int
<B>compare</B> (charT* s) const;
int
<B>compare</B> (size_type pos, size_type n1, charT* s) const;
int
<B>compare</B> (size_type pos, size_type n1, charT* s,
size_type n2) const;</PRE>
<UL><P>Return the result of a lexographical comparison between elements of this string and a given comparison string. The members return, respectively:</P>
<PRE>compare (str)</PRE>
<PRE>compare (basic_string (str, pos2, n2))
compare (basic_string(s))
compare (basic_string(s, npos))
compare (basic_string (s,n2))
</PRE></UL>
<PRE>size_type
<B>copy</B> (charT* s, size_type n, size_type pos = 0) const;</PRE>
<UL><P>Replaces elements in memory with copies of elements from this string. An <SAMP>out_of_range</SAMP> exception will be thrown if <SAMP>pos > size()</SAMP>. The lesser of <SAMP>n</SAMP> and <SAMP>size() - pos</SAMP> elements of this string, starting at position <SAMP>pos</SAMP> are copied into the array pointed to by <SAMP>s</SAMP>. No terminating null is appended to <SAMP>s</SAMP>.</P>
</UL>
<PRE>const charT*
<B>c_str</B> () const;
const charT*
<B>data</B> () const;</PRE>
<UL><P>Return a pointer to the initial element of an array whose first <SAMP>size()</SAMP> elements are copies of the elements in this string. A <SAMP>traits::eos()</SAMP> element is appended to the end. The elements of the array may not be altered, and the returned pointer is only valid until a non-<SAMP>const</SAMP> member function of this string is called. If <SAMP>size()</SAMP> is zero, the <SAMP>data()</SAMP> function returns a <SAMP>NULL</SAMP> pointer.</P>
</UL>
<PRE>bool <B>empty</B> () const;</PRE>
<UL><P>Returns <SAMP>size() == 0</SAMP>.</P>
</UL>
<PRE>basic_string&
<B>erase</B> (size_type pos = 0, size_type n = npos);
iterator
<B>erase</B> (iterator p);
iterator
<B>erase</B> (iterator first, iterator last);</PRE>
<UL><P>This function removes elements from the string, collapsing the remaining elements, as necessary, to remove any space left empty. The first version of the function removes the smaller of <SAMP>n</SAMP> and<SAMP> size() - pos </SAMP> starting at position <SAMP>pos</SAMP>. An <SAMP>out_of_range </SAMP>exception will be thrown if <SAMP> pos > size()</SAMP>. The second version requires that <SAMP>p</SAMP> is a valid iterator on this string, and removes the character referred to by <SAMP>p</SAMP>. The last version of <SAMP>erase</SAMP> requires that both <SAMP>first</SAMP> and <SAMP>last</SAMP> are valid iterators on this string, and removes the characters defined by the range <SAMP>[first, last)</SAMP>. The destructors for all removed characters are called. All versions of <SAMP>erase</SAMP> return a reference to this string after completion.</P>
</UL>
<PRE>size_type
<B>find</B> (const basic_string& str, size_type pos = 0) const;</PRE>
<UL><P>Searches for the first occurance of the substring specified by <SAMP>str</SAMP> in this string, starting at position <SAMP>pos</SAMP>. If found, it returns the index of the first character of the matching substring. If not found, returns <SAMP>npos</SAMP>. Equality is defined by <SAMP>traits::eq()</SAMP>.</P>
</UL>
<PRE>size_type
<B>find</B> (const charT* s, size_type pos, size_type n) const;
size_type
<B>find</B> (const charT* s, size_type pos = 0) const;
size_type
<B>find</B> (charT c, size_type pos = 0) const;</PRE>
<UL><P>Search for the first sequence of characters in this string that match a specified string. The variations of this function return, respectively:</P>
<PRE>find(basic_string(s,n), pos)</PRE>
<PRE>find(basic_string(s), pos)
find(basic_string(1, c), pos)</PRE></UL>
<PRE>size_type
<B>find_first_not_of</B> (const basic_string& str,
size_type pos = 0) const;</PRE>
<UL><P>Searches for the first element of this string at or after position <SAMP>pos</SAMP> that is not equal to any element of <SAMP>str</SAMP>. If found, <SAMP>find_first_not_of</SAMP> returns the index of the non-matching character. If all of the characters match, the function returns <SAMP>npos</SAMP>. Equality is defined by <SAMP>traits::eq()</SAMP>.</P>
</UL>
<PRE>size_type
<B>find_first_not_of </B> (const charT* s,
size_type pos, size_type n) const;
size_type
<B>find_first_not_of </B>(const charT* s,
size_type pos = 0) const;
size_type
<B>find_first_not_of</B> (charT c, size_type pos = 0) const;</PRE>
<UL><P>Search for the first element in this string at or after position <SAMP>pos</SAMP> that is not equal to any element of a given set of characters. The members return, respectively:</P>
<PRE>find_first_not_of(basic_string(s,n), pos)</PRE>
<PRE>find_first_not_of(basic_string(s), pos)
find_first_not_of(basic_string(1, c), pos)</PRE></UL>
<PRE>size_type
<B>find_first_of</B> (const basic_string& str,
size_type pos = 0) const;</PRE>
<UL><P>Searches for the first occurence at or after position <SAMP>pos</SAMP> of any element of <SAMP>str</SAMP> in this string. If found, the index of this matching character is returned. If not found, <SAMP>npos</SAMP> is returned. Equality is defined by <SAMP>traits::eq()</SAMP>.</P>
</UL>
<PRE>size_type
<B>find_first_of </B>(const charT* s, size_type pos,
size_type n) const;
size_type
<B>find_first_of </B>(const charT* s, size_type pos = 0) const;
size_type
<B>find_first_of </B> (charT c, size_type pos = 0) const;</PRE>
<UL><P>Search for the first occurence in this string of any element in a specified string. The <SAMP>find_first_of</SAMP> variations return, respectively:</P>
<PRE>find_first_of(basic_string(s,n), pos)</PRE>
<PRE>find_first_of(basic_string(s), pos)
find_first_of(basic_string(1, c), pos)</PRE></UL>
<PRE>size_type
<B>find_last_not_of</B> (const basic_string& str,
size_type pos = npos) const;</PRE>
<UL><P>Searches for the last element of this string at or before position <SAMP>pos</SAMP> that is not equal to any element of <SAMP>str</SAMP>. If <SAMP>find_last_not_of</SAMP> finds a non-matching element, it returns the index of the character. If all the elements match, the function returns <SAMP>npos</SAMP>. Equality is defined by <SAMP>traits::eq()</SAMP>.</P>
</UL>
<PRE>size_type
<B>find_last_not_of </B>(const charT* s,
size_type pos, size_type n) const;
size_type
<B>find_last_not_of</B> (const charT* s, size_type pos = npos) const;
size_type
<B>find_last_not_of </B>(charT c, size_type pos = npos) const;</PRE>
<UL><P>Search for the last element in this string at or before position <SAMP>pos</SAMP> that is not equal to any element of a given set of characters. The members return, respectively:</P>
<PRE>find_last_not_of(basic_string(s,n), pos)</PRE>
<PRE>find_last_not_of(basic_string(s), pos)
find_last_not_of(basic_string(1, c), pos)</PRE></UL>
<PRE>size_type
<B>find_last_of </B>(const basic_string& str,
size_type pos = npos) const; </PRE>
<UL><P>Searches for the last occurence of any element of <SAMP>str</SAMP> at or before position <SAMP>pos</SAMP> in this string. If found, <SAMP>find_last_of</SAMP> returns the index of the matching character. If not found <SAMP>find_last_of</SAMP> returns <SAMP>npos</SAMP>. Equality is defined by <SAMP>traits::eq()</SAMP>.</P>
</UL>
<PRE>size_type
<B>find_last_of</B> (const charT* s, size_type pos,
size_type n) const;
size_type
<B>find_last_of</B> (const charT* s, size_type pos = npos) const;
size_type
<B>find_last_of</B> (charT c, size_type pos = npos) const;</PRE>
<UL><P>Search for the last occurence in this string of any element in a specified string. The members return, respectively:</P>
<PRE>find_last_of(basic_string(s,n), pos)</PRE>
<PRE>find_last_of(basic_string(s), pos)
find_last_of(basic_string(1, c), pos)</PRE></UL>
<PRE>basic_string&
<B>insert</B> (size_type pos1, const basic_string& s);
basic_string&
<B>insert</B> (size_type pos, const basic_string& s,
size_type pos2 = 0, size_type n = npos);
basic_string&
<B>insert</B> (size_type pos, const charT* s, size_type n);
basic_string&
<B>insert</B> (size_type pos, const charT* s);
basic_string&
<B>insert</B> (size_type pos, size_type n, charT c);</PRE>
<UL><P>Insert additional elements at position <SAMP>pos</SAMP> in this string. All of the variants of this function will throw an <SAMP>out_of_range</SAMP> exception if <SAMP>pos > size()</SAMP>. All variants will also throw a <SAMP>length_error</SAMP> if the resulting string will exceed <SAMP>max_size()</SAMP>. Elements of this string will be moved apart as necessary to accommodate the inserted elements. All return a reference to this string after completion.</P>
<P>The second variation of this function inserts the lesser of <SAMP>n</SAMP> and <SAMP>s.size() - pos2</SAMP> characters of <SAMP>s</SAMP>, beginning at position <SAMP>pos2</SAMP> in this string. This version will throw an <SAMP>out_of_range</SAMP> exception if <SAMP>pos2 > s.size()</SAMP>. The third version inserts <SAMP>n</SAMP> characters of the array pointed to by <SAMP>s</SAMP>. The fourth inserts elements from the array pointed to by <SAMP>s</SAMP> up to, but not including, a <SAMP>traits::eos()</SAMP> character. Finally, the fifth variation inserts <SAMP>n</SAMP> repetitions of <SAMP>c</SAMP>.</P>
</UL>
<PRE>iterator
<B>insert</B> (iterator p, charT c = charT());
void
<B>insert</B> (iterator p, size_type n, charT c);
template<class InputIterator>
void
<B>insert</B> (iterator p, InputIterator first, InputIterator last);</PRE>
<UL><P>Insert additional elements in this string immediately before the character referred to by <SAMP>p</SAMP>. All of these versions of <SAMP>insert</SAMP> require that <SAMP>p</SAMP> is a valid iterator on this string. The first version inserts a copy of <SAMP>c</SAMP>. The second version inserts <SAMP>n</SAMP> repetitions of <SAMP>c</SAMP>. The third version inserts characters in the range <SAMP>[first, last).</SAMP> The first version returns <SAMP>p</SAMP>.</P>
</UL>
<PRE>size_type
<B>length</B> () const;</PRE>
<UL><P>Return the number of elements contained in this string.</P>
</UL>
<PRE>size_type
<B>max_size</B> () const;</PRE>
<UL><P>Returns the maximum possible size of the string.</P>
</UL>
<PRE>size_type
<B>rfind</B> (const basic_string& str, size_type pos = npos) const;</PRE>
<UL><P>Searches for the last occurrence of the substring specified by <SAMP>str</SAMP> in this string, starting at position <SAMP>pos</SAMP>. Note that only the first character of the substring must be <SAMP><= pos;</SAMP> the remaining characters may extend beyond <SAMP>pos</SAMP>. If found, the index of the first character of that matches substring is returned. If not found, <SAMP>npos</SAMP> is returned. Equality is defined by <SAMP>traits::eq()</SAMP>.</P>
</UL>
<PRE>size_type
<B>rfind</B> (const charT* s, size_type pos, size_type n) const;
size_type
<B>rfind</B> (const charT* s, size_type pos = npos) const;
size_type
<B>rfind</B> (charT c, size_type pos = npos) const;</PRE>
<UL><P>Searches for the last sequence of characters in this string matching a specified string. The <SAMP>rfind</SAMP> variations return, respectively:</P>
<PRE>rfind(basic_string(s,n), pos)</PRE>
<PRE>rfind(basic_string(s), pos)
rfind(basic_string(1, c), pos)</PRE></UL>
<PRE>basic_string&
<B>replace</B> (size_type pos, size_type n1, const basic_string& s);
basic_string&
<B>replace</B> (size_type pos1, size_type n1, const basic_string& str,
size_type pos2, size_type n2);
basic_string&
<B>replace</B> (size_type pos, size_type n1, const charT* s,
size_type n2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -