📄 basic_string.html
字号:
<TD VAlign=top><pre>template <class charT, class traits, class Alloc>basic_string<charT, traits, Alloc>operator+(charT c, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String concatenation. A global function, not a member function.</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, charT c)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String concatenation. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator==(const basic_string<charT, traits, Alloc>& s1, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>String equality. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator==(const charT* s1, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String equality. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator==(const basic_string<charT, traits, Alloc>& s1, const charT* s2)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String equality. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator!=(const basic_string<charT, traits, Alloc>& s1, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>String inequality. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator!=(const charT* s1, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String inequality. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator!=(const basic_string<charT, traits, Alloc>& s1, const charT* s2)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String inequality. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator<(const basic_string<charT, traits, Alloc>& s1, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>String comparison. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator<(const charT* s1, const basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String comparison. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>bool operator<(const basic_string<charT, traits, Alloc>& s1, const charT* s2)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>String comparison. A global function, not a member function.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>void swap(basic_string<charT, traits, Alloc>& s1, basic_string<charT, traits, Alloc>& s2)</pre></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Swaps the contents of two strings.</TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Alloc>& s)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>Reads <tt>s</tt> from the input stream <tt>is</tt></TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>basic_ostream<charT, traits>&operator<<(basic_istream<charT, traits>& os, const basic_string<charT, traits, Alloc>& s)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>Writes <tt>s</tt> to the output stream <tt>os</tt></TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>basic_istream<charT, traits>&getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Alloc>& s, charT delim)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>Reads a string from the input stream <tt>is</tt>, stopping when it reaches <tt>delim</tt></TD></TR><TR><TD VAlign=top><pre>template <class charT, class traits, class Alloc>basic_istream<charT, traits>&getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Alloc>& s)</pre></TD><TD VAlign=top><tt>basic_string</tt></TD><TD VAlign=top>Reads a single line from the input stream <tt>is</tt></TD></tr></table><h3>New members</h3>These members are not defined in the <A href="RandomAccessContainer.html">Random Access Container</A> and <A href="Sequence.html">Sequence</A>:requirements, but are specific to <tt>basic_string</tt>.<Table border><TR><TH>Member</TH><TH>Description</TH></TR><TR><TD VAlign=top><tt>static const size_type npos</tt></TD><TD VAlign=top>The largest possible value of type <tt>size_type</tt>. That is, <tt>size_type(-1)</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type length() const</tt></TD><TD VAlign=top>Equivalent to <tt>size()</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type capacity() const</tt></TD><TD VAlign=top>Number of elements for which memory has been allocated. That is, the size to which the string can grow before memory must be reallocated. <tt>capacity()</tt> is always greater than or equal to <tt>size()</tt>. </TD></TR><TR><TD VAlign=top><tt>const charT* c_str() const</tt></TD><TD VAlign=top>Returns a pointer to a null-terminated array of characters representing the string's contents. For any string <tt>s</tt> it is guaranteed that the first <tt>s.size()</tt> characters in the array pointed to by <tt>s.c_str()</tt> are equal to the character in <tt>s</tt>, and that <tt>s.c_str()[s.size()]</tt> is a null character. Note, however, that it not necessarily the first null character. Characters within a string are permitted to be null.</TD></TR><TR><TD VAlign=top><tt>const charT* data() const</tt></TD><TD VAlign=top>Returns a pointer to an array of characters, not necessarily null-terminated, representing the string's contents. <tt>data()</tt> is permitted, but not required, to be identical to <tt>c_str()</tt>. The first <tt>size()</tt> characters of that array are guaranteed to be identical to the characters in <tt>*this</tt>. The return value of <tt>data()</tt> is never a null pointer, even if <tt>size()</tt> is zero.</TD></TR><TR><TD VAlign=top><tt>basic_string(const basic_string& s, size_type pos = 0, size_type n = npos)</tt></TD><TD VAlign=top>Constructs a string from a substring of <tt>s</tt>. The substring begins at character position <tt>pos</tt> and terminates at character position <tt>pos + n</tt> or at the end of <tt>s</tt>, whichever comes first. This constructor throws <tt>out_of_range</tt> if <tt>pos > s.size()</tt>. Note that when <tt>pos</tt> and <tt>n</tt> have their default values, this is just a copy constructor.</TD></TR><TR><TD VAlign=top><tt>basic_string(const charT* s)</tt></TD><TD VAlign=top>Equivalent to <tt>basic_string(s, s + traits::length(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string(const charT* s, size_type n)</tt></TD><TD VAlign=top>Equivalent to <tt>basic_string(s, s + n)</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& operator=(const charT* s)</tt></TD><TD VAlign=top>Equivalent to <tt>operator=(basic_string(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& operator=(charT c)</tt></TD><TD VAlign=top>Assigns to <tt>*this</tt> a string whose size is <tt>1</tt> and whose contents is the single character <tt>c</tt>.</TD></TR><TR><TD VAlign=top><tt>void reserve(size_t n)</tt></TD><TD VAlign=top>Requests that the string's capacity be changed; the postcondition for this member function is that, after it is called, <tt>capacity() >= n</tt>. You may request that a string decrease its capacity by calling <tt>reserve()</tt> with an argument less than the current capacity. (If you call <tt>reserve()</tt> with an argument less than the string's size, however, the capacity will only be reduced to <tt>size()</tt>. A string's size can never be greater than its capacity.) <tt>reserve()</tt> throws <tt>length_error</tt> if <tt>n > max_size()</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& insert(size_type pos, const basic_string& s)</tt></TD><TD VAlign=top>If <tt>pos > size()</tt>, throws <tt>out_of_range</tt>. Otherwise, equivalent to <tt>insert(begin() + pos, s.begin(), s.end())</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& insert(size_type pos, const basic_string& s, size_type pos1, size_type n)</pre></TD><TD VAlign=top>If <tt>pos > size()</tt> or <tt>pos1 > s.size()</tt>, throws <tt>out_of_range</tt>. Otherwise, equivalent to <tt>insert(begin() + pos, s.begin() + pos1, s.begin() + pos1 + min(n, s.size() - pos1))</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& insert(size_type pos, const charT* s)</tt></TD><TD VAlign=top>If <tt>pos > size()</tt>, throws <tt>out_of_range</tt>. Otherwise, equivalent to <tt>insert(begin() + pos, s, s + traits::length(s))</tt></TD></TR><TR><TD VAlign=top><tt>basic_string& insert(size_type pos, const charT* s, size_type n)</tt></TD><TD VAlign=top>If <tt>pos > size()</tt>, throws <tt>out_of_range</tt>. Otherwise, equivalent to <tt>insert(begin() + pos, s, s + n)</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& insert(size_type pos, size_type n, charT c)</tt></TD><TD VAlign=top>If <tt>pos > size()</tt>, throws <tt>out_of_range</tt>. Otherwise, equivalent to <tt>insert(begin() + pos, n, c)</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& append(const basic_string& s)</tt></TD><TD VAlign=top>Equivalent to <tt>insert(end(), s.begin(), s.end())</tt>.</TD></TR><TR><TD VAlign=top><pre>basic_string& append(const basic_string& s, size_type pos, size_type n)</pre></TD><TD VAlign=top>If <tt>pos > s.size()</tt>, throws <tt>out_of_range</tt>. Otherwise, equivalent to <tt>insert(end(), s.begin() + pos, s.begin() + pos + min(n, s.size() - pos))</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& append(const charT* s)</tt></TD><TD VAlign=top>Equivalent to <tt>insert(end(), s, s + traits::length(s))</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& append(const charT* s, size_type n)</tt></TD><TD VAlign=top>Equivalent to <tt>insert(end(), s, s + n)</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& append(size_type n, charT c)</tt></TD><TD VAlign=top>Equivalent to <tt>insert(end(), n, c)</tt>.</TD></TR><TR><TD VAlign=top><pre>template <class InputIterator>basic_string& append(InputIterator first, InputIterator last)</pre></TD><TD VAlign=top>Equivalent to <tt>insert(end(), first, last)</tt>.</TD></TR><TR><TD VAlign=top><tt>void push_back(charT c)</tt></TD><TD VAlign=top>Equivalent to <tt>insert(end(), c)</tt></TD></TR><TR><TD VAlign=top><tt>basic_string& operator+=(const basic_string& s)</tt></TD><TD VAlign=top>Equivalent to <tt>append(s)</tt>.</TD></TR><TR><TD VAlign=top><tt>basic_string& operator+=(const charT* s)</tt></TD><TD VAlign=top>Equivalent to <tt>append(s)</tt></TD></TR><TR><TD VAlign=top><tt>basic_string& operator+=(charT c)</tt></TD><TD VAlign=top>Equivalent to <tt>push_back(c)</tt></TD></TR><TR><TD VAlign=top><tt>basic_string& erase(size_type pos = 0, size_type n = npos)</tt>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -