📄 basic_string.html
字号:
</TD><TD VAlign=top>If <tt>pos > size()</tt>, throws <tt>out_of_range</tt>. Otherwise, equivalent to <tt>erase(begin() + pos, begin() + pos + min(n, size() - pos))</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& assign(const basic_string& s)</tt></TD><TD VAlign=top>Synonym for <tt>operator=</tt></TD></TR><TR><TD VAlign=top><pre>basic_string& assign(const basic_string& s, size_type pos, size_type n)</pre></TD><TD VAlign=top>Equivalent to (but probably faster than) <tt>clear()</tt> followed by <tt>insert(0, s, pos, n)</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& assign(const charT* s, size_type n)</tt></TD><TD VAlign=top>Equivalent to (but probably faster than) <tt>clear()</tt> followed by <tt>insert(0, s, n)</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& assign(const charT* s)</tt></TD><TD VAlign=top>Equivalent to (but probably faster than) <tt>clear()</tt> followed by <tt>insert(0, s)</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(size_type pos, size_type n, const basic_string& s)</pre></TD><TD VAlign=top>Equivalent to <tt>erase(pos, n)</tt> followed by <tt>insert(pos, s)</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(size_type pos, size_type n, const basic_string& s, size_type pos1, size_type n1)</pre></TD><TD VAlign=top>Equivalent to <tt>erase(pos, n)</tt> followed by <tt>insert(pos, s, pos1, n1)</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(size_type pos, size_type n, const charT* s, size_type n1)</pre></TD><TD VAlign=top>Equivalent to <tt>erase(pos, n)</tt> followed by <tt>insert(pos, s, n1)</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(size_type pos, size_type n, const charT* s)</pre></TD><TD VAlign=top>Equivalent to <tt>erase(pos, n)</tt> followed by <tt>insert(pos, s)</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(size_type pos, size_type n, size_type n1, charT c)</pre></TD><TD VAlign=top>Equivalent to <tt>erase(pos, n)</tt> followed by <tt>insert(pos, n1, c)</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(iterator first, iterator last, const basic_string& s)</pre></TD><TD VAlign=top>Equivalent to <tt>insert(erase(first, last), s.begin(), s.end())</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(iterator first, iterator last, const charT* s, size_type n)</pre></TD><TD VAlign=top>Equivalent to <tt>insert(erase(first, last), s, s + n)</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(iterator first, iterator last, const charT* s)</pre></TD><TD VAlign=top>Equivalent to <tt>insert(erase(first, last), s, s + traits::length(s))</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& replace(iterator first, iterator last, size_type n, charT c)</pre></TD><TD VAlign=top>Equivalent to <tt>insert(erase(first, last), n, c)</tt>.</TD></TR><TR><TD VAlign=top><pre>template <class InputIterator>basic_string& replace(iterator first, iterator last, InputIterator f, InputIterator l)</pre></TD><TD VAlign=top>Equivalent to <tt>insert(erase(first, last), f, l)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type copy(charT* buf, size_type n, size_type pos = 0) const</tt></TD><TD VAlign=top>Copies at most <tt>n</tt> characters from <tt>*this</tt> to a character array. Throws <tt>out_of_range</tt> if <tt>pos > size()</tt>. Otherwise, equivalent to <tt><A href="copy.html">copy</A>(begin() + pos, begin() + pos + min(n, size()), buf)</tt>. Note that this member function does nothing other than copy characters from <tt>*this</tt> to <tt>buf</tt>; in particular, it does not terminate <tt>buf</tt> with a null character.</TD></TR><TR><TD VAlign=top><tt>size_type find(const basic_string& s, size_type pos = 0) const</tt></TD><TD VAlign=top>Searches for <tt>s</tt> as a substring of <tt>*this</tt>, beginning at character position <tt>pos</tt>. It is almost the same as <tt><A href="search.html">search</A></tt>, except that <tt><A href="search.html">search</A></tt> tests elements for equality using <tt>operator==</tt> or a user-provided function object, while this member function uses <tt>traits::eq</tt>. Returns the lowest character position <tt>N</tt> such that <tt>pos <= N</tt> and <tt>pos + s.size() <= size()</tt> and such that, for every <tt>i</tt> less than <tt>s.size()</tt>, <tt>(*this)[N + i]</tt> compares equal to <tt>s[i]</tt>. Returns <tt>npos</tt> if no such position <tt>N</tt> exists. Note that it is legal to call this member function with arguments such that <tt>s.size() > size() - pos</tt>, but such a search will always fail.</TD></TR><TR><TD VAlign=top><tt>size_type find(const charT* s, size_type pos, size_type n) const</tt></TD><TD VAlign=top>Searches for the first <tt>n</tt> characters of <tt>s</tt> as a substring of <tt>*this</tt>, beginning at character <tt>pos</tt> of <tt>*this</tt>. This is equivalent to <tt>find(basic_string(s, n), pos)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find(const charT* s, size_type pos = 0) const</tt></TD><TD VAlign=top>Searches for a null-terminated character array as a substring of <tt>*this</tt>, beginning at character <tt>pos</tt> of <tt>*this</tt>. This is equivalent to <tt>find(basic_string(s), pos)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find(charT c, size_type pos = 0) const</tt></TD><TD VAlign=top>Searches for the character <tt>c</tt>, beginning at character position <tt>pos</tt>. That is, returns the first character position <tt>N</tt> greater than or equal to <tt>pos</tt>, and less than <tt>size()</tt>, such that <tt>(*this)[N]</tt> compares equal to <tt>c</tt>. Returns <tt>npos</tt> if no such character position <tt>N</tt> exists.</TD></TR><TR><TD VAlign=top><tt>size_type rfind(const basic_string& s, size_type pos = npos) const</tt></TD><TD VAlign=top>Searches backward for <tt>s</tt> as a substring of <tt>*this</tt>. It is almost the same as <tt><A href="find_end.html">find_end</A></tt>, except that <tt><A href="find_end.html">find_end</A></tt> tests elements for equality using <tt>operator==</tt> or a user-provided function object, while this member function uses <tt>traits::eq</tt>. This member function returns the largest character position <tt>N</tt> such that <tt>N <= pos</tt> and <tt>N + s.size() <= size()</tt>, and such that, for every <tt>i</tt> less than <tt>s.size()</tt>, <tt>(*this)[N + i]</tt> compares equal to <tt>s[i]</tt>. Returns <tt>npos</tt> if no such position <tt>N</tt> exists. Note that it is legal to call this member function with arguments such that <tt>s.size() > size()</tt>, but such a search will always fail.</TD></TR><TR><TD VAlign=top><tt>size_type rfind(const charT* s, size_type pos, size_type n) const</tt></TD><TD VAlign=top>Searches backward for the first <tt>n</tt> characters of <tt>s</tt> as a substring of <tt>*this</tt>. Equivalent to <tt>rfind(basic_string(s, n), pos)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type rfind(const charT* s, size_type pos = npos) const</tt></TD><TD VAlign=top>Searches backward for a null-terminated character array as a substring of <tt>*this</tt>. Equivalent to <tt>rfind(basic_string(s), pos)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type rfind(charT c, size_type pos = npos) const</tt></TD><TD VAlign=top>Searches backward for the character <tt>c</tt>. That is, returns the largest character position <tt>N</tt> such that <tt>N <= pos</tt> and <tt>N < size()</tt>, and such that <tt>(*this)[N]</tt> compares equal to <tt>c</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_of(const basic_string& s, size_type pos = 0) const</tt></TD><TD VAlign=top>Searches within <tt>*this</tt>, beginning at <tt>pos</tt>, for the first character that is equal to any character within <tt>s</tt>. This is similar to the standard algorithm <tt><A href="find_first_of.html">find_first_of</A></tt>, but differs because <tt><A href="find_first_of.html">find_first_of</A></tt> compares characters using <tt>operator==</tt> or a user-provided function object, while this member function uses <tt>traits::eq</tt>. Returns the smallest character position <tt>N</tt> such that <tt>pos <= N < size()</tt>, and such that <tt>(*this)[N]</tt> compares equal to some character within <tt>s</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_of(const charT* s, size_type pos, size_type n) const</tt></TD><TD VAlign=top>Searches within <tt>*this</tt>, beginning at <tt>pos</tt>, for the first character that is equal to any character within the range <tt>[s, s+n)</tt>. That is, returns the smallest character position <tt>N</tt> such that <tt>pos <= N < size()</tt>, and such that <tt>(*this)[N]</tt> compares equal to some character in <tt>[s, s+n)</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_of(const charT* s, size_type pos = 0) const</tt></TD><TD VAlign=top>Equivalent to <tt>find_first_of(s, pos, traits::length(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_of(charT c, size_type pos = 0) const</tt></TD><TD VAlign=top>Equivalent to <tt>find(c, pos)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_not_of(const basic_string& s, size_type pos = 0) const</tt></TD><TD VAlign=top>Searches within <tt>*this</tt>, beginning at <tt>pos</tt>, for the first character that is not equal to any character within <tt>s</tt>. Returns the smallest character position <tt>N</tt> such that <tt>pos <= N < size()</tt>, and such that <tt>(*this)[N]</tt> does not compare equal to any character within <tt>s</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_not_of(const charT* s, size_type pos, size_type n) const</tt></TD><TD VAlign=top>Searches within <tt>*this</tt>, beginning at <tt>pos</tt>, for the first character that is not equal to any character within the range <tt>[s, s+n)</tt>. That is, returns the smallest character position <tt>N</tt> such that <tt>pos <= N < size()</tt>, and such that <tt>(*this)[N]</tt> does not compare equal to any character in <tt>[s, s+n)</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_not_of(const charT* s, size_type pos = 0) const</tt></TD><TD VAlign=top>Equivalent to <tt>find_first_not_of(s, pos, traits::length(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find_first_not_of(charT c, size_type pos = 0) const</tt></TD><TD VAlign=top>Returns the smallest character position <tt>N</tt> such that <tt>pos <= N < size()</tt>, and such that <tt>(*this)[N]</tt> does not compare equal to <tt>c</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_of(const basic_string& s, size_type pos = npos) const</tt></TD><TD VAlign=top>Searches backward within <tt>*this</tt> for the first character that is equal to any character within <tt>s</tt>. That is, returns the largest character position <tt>N</tt> such that <tt>N <= pos</tt> and <tt>N < size()</tt>, and such that <tt>(*this)[N]</tt> compares equal to some character within <tt>s</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_of(const charT* s, size_type pos, size_type n) const</tt></TD><TD VAlign=top>Searches backward within <tt>*this</tt> for the first character that is equal to any character within the range <tt>[s, s+n)</tt>. That is, returns the largest character position <tt>N</tt> such that <tt>N <= pos</tt> and <tt>N < size()</tt>, and such that <tt>(*this)[N]</tt> compares equal to some character within <tt>[s, s+n)</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_of(const charT* s, size_type pos = npos) const</tt></TD><TD VAlign=top>Equivalent to <tt>find_last_of(s, pos, traits::length(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_of(charT c, size_type pos = npos) const</tt></TD><TD VAlign=top>Equivalent to <tt>rfind(c, pos)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_not_of(const basic_string& s, size_type pos = npos) const</tt></TD><TD VAlign=top>Searches backward within <tt>*this</tt> for the first character that is not equal to any character within <tt>s</tt>. That is, returns the largest character position <tt>N</tt> such that <tt>N <= pos</tt> and <tt>N < size()</tt>, and such that <tt>(*this)[N]</tt> does not compare equal to any character within <tt>s</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_not_of(const charT* s, size_type pos, size_type n) const</tt></TD><TD VAlign=top>Searches backward within <tt>*this</tt> for the first character that is not equal to any character within <tt>[s, s+n)</tt>. That is, returns the largest character position <tt>N</tt> such that <tt>N <= pos</tt> and <tt>N < size()</tt>, and such that <tt>(*this)[N]</tt> does not compare equal to any character within <tt>[s, s+n)</tt>. Returns <tt>npos</tt> if no such character position exists.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_not_of(const charT* s, size_type pos = npos) const</tt></TD><TD VAlign=top>Equivalent to <tt>find_last_of(s, pos, traits::length(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type find_last_not_of(charT c, size_type pos = npos) const</tt></TD><TD VAlign=top>Searches backward <tt>*this</tt> for the first character that is not equal to <tt>c</tt>. That is, returns the largest character position <tt>N</tt> such that <tt>N <= pos</tt> and <tt>N < size()</tt>, and such that <tt>(*this)[N]</tt> does not compare equal to <tt>c</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string substr(size_type pos = 0, size_type n = npos) const</tt></TD><TD VAlign=top>Equivalent to <tt>basic_string(*this, pos, n)</tt>.</TD></TR><TR><TD VAlign=top><tt>int compare(const basic_string& s) const</tt></TD><TD VAlign=top>Three-way lexicographical comparison of <tt>s</tt> and <tt>*this</tt>, much like <tt>strcmp</tt>. If <tt>traits::compare(data, s.data(), min(size(), s.size()))</tt> is nonzero, then it returns that nonzero value. Otherwise returns a negative number if <tt>size() < s.size()</tt>, a positive number if <tt>size() > s.size()</tt>, and zero if the two are equal.</TD></TR><TR><TD VAlign=top><tt>int compare(size_type pos, size_type n, const basic_string& s) const</tt></TD><TD VAlign=top>Three-way lexicographical comparison of <tt>s</tt> and a substring of <tt>*this</tt>. Equivalent to <tt>basic_string(*this, pos, n).compare(s)</tt>.</TD></TR><TR><TD VAlign=top><tt>int compare(size_type pos, size_type n, const basic_string& s, size_type pos1, size_type n1) const</tt></TD><TD VAlign=top>Three-way lexicographical comparison of a substring of <tt>s</tt> and a substring of <tt>*this</tt>. Equivalent to <tt>basic_string(*this, pos, n).compare(basic_string(s, pos1, n1))</tt>.</TD></TR><TR><TD VAlign=top><tt>int compare(const charT* s) const</tt></TD><TD VAlign=top>Three-way lexicographical comparison of <tt>s</tt> and <tt>*this</tt>. Equivalent to <tt>compare(basic_string(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>int compare(size_type pos, size_type n, const charT* s, size_type len = npos) const</tt></TD><TD VAlign=top>Three-way lexicographical comparison of the first <tt>min(len, traits::length(s)</tt> characters of <tt>s</tt> and a substring of <tt>*this</tt>. Equivalent to <tt>basic_string(*this, pos, n).compare(basic_string(s, min(len, traits::length(s))))</tt>. </TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>basic_string<charT, traits, Alloc>operator+(const basic_string<charT, traits, Alloc>& s1, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top>String concatenation. Equivalent to creating a temporary copy of <tt>s</tt>, appending <tt>s2</tt>, and then returning the temporary copy.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>basic_string<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -