📄 string2.html
字号:
reference <B><A HREF="#basic_string::at">at</A></B>(size_type off); const_reference <B><A HREF="#basic_string::operator[]">operator[]</A></B>(size_type off) const; reference <B><A HREF="#basic_string::operator[]">operator[]</A></B>(size_type off); void <B><A HREF="#basic_string::push_back">push_back</A></B>(value_type ch); const value_type *<B><A HREF="#basic_string::c_str">c_str</A></B>() const; const value_type *<B><A HREF="#basic_string::data">data</A></B>() const; size_type <B><A HREF="#basic_string::length">length</A></B>() const; size_type <B><A HREF="#basic_string::size">size</A></B>() const; size_type <B><A HREF="#basic_string::max_size">max_size</A></B>() const; void <B><A HREF="#basic_string::resize">resize</A></B>(size_type newsize, value_type ch = value_type()); size_type <B><A HREF="#basic_string::capacity">capacity</A></B>() const; void <B><A HREF="#basic_string::reserve">reserve</A></B>(size_type count = 0); bool <B><A HREF="#basic_string::empty">empty</A></B>() const; basic_string& <B><A HREF="#basic_string::operator+=">operator+=</A></B>(const basic_string& right); basic_string& <B><A HREF="#basic_string::operator+=">operator+=</A></B>(const value_type *ptr); basic_string& <B><A HREF="#basic_string::operator+=">operator+=</A></B>(value_type ch);</PRE><PRE> basic_string& <B><A HREF="#basic_string::append">append</A></B>(const basic_string& right); basic_string& <B><A HREF="#basic_string::append">append</A></B>(const basic_string& right, size_type roff, size_type count); basic_string& <B><A HREF="#basic_string::append">append</A></B>(const value_type *ptr, size_type count); basic_string& <B><A HREF="#basic_string::append">append</A></B>(const value_type *ptr); basic_string& <B><A HREF="#basic_string::append">append</A></B>(size_type count, value_type ch); template<class InIt> basic_string& <B><A HREF="#basic_string::append">append</A></B>(InIt first, InIt last); basic_string& <B><A HREF="#basic_string::assign">assign</A></B>(const basic_string& right); basic_string& <B><A HREF="#basic_string::assign">assign</A></B>(const basic_string& right, size_type roff, size_type count); basic_string& <B><A HREF="#basic_string::assign">assign</A></B>(const value_type *ptr, size_type count); basic_string& <B><A HREF="#basic_string::assign">assign</A></B>(const value_type *ptr); basic_string& <B><A HREF="#basic_string::assign">assign</A></B>(size_type count, value_type ch); template<class InIt> basic_string& <B><A HREF="#basic_string::assign">assign</A></B>(InIt first, InIt last); basic_string& <B><A HREF="#basic_string::insert">insert</A></B>(size_type off, const basic_string& right); basic_string& <B><A HREF="#basic_string::insert">insert</A></B>(size_type off, const basic_string& right, size_type roff, size_type count); basic_string& <B><A HREF="#basic_string::insert">insert</A></B>(size_type off, const value_type *ptr, size_type count); basic_string& <B><A HREF="#basic_string::insert">insert</A></B>(size_type off, const value_type *ptr); basic_string& <B><A HREF="#basic_string::insert">insert</A></B>(size_type off, size_type count, value_type ch); iterator <B><A HREF="#basic_string::insert">insert</A></B>(iterator where, value_type ch = value_type()); void <B><A HREF="#basic_string::insert">insert</A></B>(iterator where, size_type count, value_type ch); template<class InIt> void <B><A HREF="#basic_string::insert">insert</A></B>(iterator where, InIt first, InIt last); basic_string& <B><A HREF="#basic_string::erase">erase</A></B>(size_type off = 0, size_type count = npos); iterator <B><A HREF="#basic_string::erase">erase</A></B>(iterator where); iterator <B><A HREF="#basic_string::erase">erase</A></B>(iterator first, iterator last); void <B><A HREF="#basic_string::clear">clear</A></B>(); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(size_type off, size_type n0, const basic_string& right); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(size_type off, size_type n0, const basic_string& right, size_type roff, size_type count); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(size_type off, size_type n0, const value_type *ptr, size_type count); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(size_type off, size_type n0, const value_type *ptr); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(size_type off, size_type n0, size_type count, value_type ch); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(iterator first, iterator last, const basic_string& right); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(iterator first, iterator last, const value_type *ptr, size_type count); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(iterator first, iterator last, const value_type *ptr); basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(iterator first, iterator last, size_type count, value_type ch); template<class InIt> basic_string& <B><A HREF="#basic_string::replace">replace</A></B>(iterator first, iterator last, InIt first2, InIt last2); size_type <B><A HREF="#basic_string::copy">copy</A></B>(value_type *ptr, size_type count, size_type off = 0) const; void <B><A HREF="#basic_string::swap">swap</A></B>(basic_string& right);</PRE><PRE> size_type <B><A HREF="#basic_string::find">find</A></B>(const basic_string& right, size_type off = 0) const; size_type <B><A HREF="#basic_string::find">find</A></B>(const value_type *ptr, size_type off, size_type count) const; size_type <B><A HREF="#basic_string::find">find</A></B>(const value_type *ptr, size_type off = 0) const; size_type <B><A HREF="#basic_string::find">find</A></B>(value_type ch, size_type off = 0) const; size_type <B><A HREF="#basic_string::find">rfind</A></B>(const basic_string& right, size_type off = npos) const; size_type <B><A HREF="#basic_string::rfind">rfind</A></B>(const value_type *ptr, size_type off, size_type count = npos) const; size_type <B><A HREF="#basic_string::rfind">rfind</A></B>(const value_type *ptr, size_type off = npos) const; size_type <B><A HREF="#basic_string::rfind">rfind</A></B>(value_type ch, size_type off = npos) const; size_type <B><A HREF="#basic_string::rfind">find_first_of</A></B>(const basic_string& right, size_type off = 0) const; size_type <B><A HREF="#basic_string::rfind">find_first_of</A></B>(const value_type *ptr, size_type off, size_type count) const; size_type <B><A HREF="#basic_string::find_first_of">find_first_of</A></B>(const value_type *ptr, size_type off = 0) const; size_type <B><A HREF="#basic_string::find_first_of">find_first_of</A></B>(value_type ch, size_type off = 0) const; size_type <B><A HREF="#basic_string::find_last_of">find_last_of</A></B>(const basic_string& right, size_type off = npos) const; size_type <B><A HREF="#basic_string::find_last_of">find_last_of</A></B>(const value_type *ptr, size_type off, size_type count = npos) const; size_type <B><A HREF="#basic_string::find_last_of">find_last_of</A></B>(const value_type *ptr, size_type off = npos) const; size_type <B><A HREF="#basic_string::find_last_of">find_last_of</A></B>(value_type ch, size_type off = npos) const; size_type <B><A HREF="#basic_string::find_first_not_of">find_first_not_of</A></B>(const basic_string& right, size_type off = 0) const; size_type <B><A HREF="#basic_string::find_first_not_of">find_first_not_of</A></B>(const value_type *ptr, size_type off, size_type count) const; size_type <B><A HREF="#basic_string::find_first_not_of">find_first_not_of</A></B>(const value_type *ptr, size_type off = 0) const; size_type <B><A HREF="#basic_string::find_first_not_of">find_first_not_of</A></B>(value_type ch, size_type off = 0) const; size_type <B><A HREF="#basic_string::find_last_not_of">find_last_not_of</A></B>(const basic_string& right, size_type off = npos) const; size_type <B><A HREF="#basic_string::find_last_not_of">find_last_not_of</A></B>(const value_type *ptr, size_type off, size_type count) const; size_type <B><A HREF="#basic_string::find_last_not_of">find_last_not_of</A></B>(const value_type *ptr, size_type off = npos) const; size_type <B><A HREF="#basic_string::find_last_not_of">find_last_not_of</A></B>(value_type ch, size_type off = npos) const; basic_string <B><A HREF="#basic_string::substr">substr</A></B>(size_type off = 0, size_type count = npos) const; int <B><A HREF="#basic_string::compare">compare</A></B>(const basic_string& right) const; int <B><A HREF="#basic_string::compare">compare</A></B>(size_type off, size_type n0, const basic_string& right) const; int <B><A HREF="#basic_string::compare">compare</A></B>(size_type off, size_type n0, const basic_string& right, size_type roff, size_type count) const; int <B><A HREF="#basic_string::compare">compare</A></B>(const value_type *ptr) const; int <B><A HREF="#basic_string::compare">compare</A></B>(size_type off, size_type n0, const value_type *ptr) const; int <B><A HREF="#basic_string::compare">compare</A></B>(size_type off, size_type n0, const value_type *ptr, size_type off) const; allocator_type <B><A HREF="#basic_string::get_allocator">get_allocator</A></B>() const; };</PRE><P>The template class describes an object that controls avarying-length sequence of elements of type <CODE>Elem</CODE>,also known as<CODE><A HREF="#basic_string::value_type">value_type</A></CODE>.Such an element type must not require explicit construction ordestruction, and it must be suitable for use as the <CODE>Elem</CODE>parameter to<A HREF="istream.html#basic_istream"><CODE>basic_istream</CODE></A> or<A HREF="ostream.html#basic_ostream"><CODE>basic_ostream</CODE></A>.(A ``plain old data structure,'' or<B><A NAME="POD">POD</A></B>, from C generally meetsthis criterion.)The Standard C++ library provides two specializations of this templateclass, with the type definitions<A HREF="#string"><CODE>string</CODE></A>,for elements of type <I>char,</I> and<A HREF="#wstring"><CODE>wstring</CODE></A>, for elements of type<CODE>wchar_t</CODE>.</P><P>Various important properties of the elementsin a <CODE>basic_string</CODE>specialization are described by the class <CODE>Tr</CODE>, also known as<CODE><A HREF="#basic_string::traits_type">traits_type</A></CODE>.A class that specifies these<A HREF="#character traits">character traits</A> musthave the same external interface as an object of template class<A HREF="#char_traits"><CODE>char_traits</CODE></A>.</P><P>The object allocates and frees storage for the sequence it controlsthrough a stored <A HREF="memory.html#allocator object">allocator object</A>of class <CODE>Alloc</CODE>, also known as<CODE><A HREF="#basic_string::allocator_type">allocator_type</A></CODE>.Such an allocator object must havethe same external interface as an object of template class<A HREF="memory.html#allocator"><CODE>allocator</CODE></A>.(Class<A HREF="#char_traits"><CODE>char_traits</CODE></A> hasno provision for alternate addressing schemes, such as might be requiredto implement a<A HREF="memory.html#far heap">far heap</A>.)Note that the stored allocator object is <I>not</I> copied when the containerobject is assigned.</P><P>The sequences controlled by an object of template class<CODE>basic_string</CODE> are usually called<B><A NAME="strings">strings</A></B>. These objects should not beconfused, however, with the null-terminated<A HREF="lib_over.html#C string">C strings</A> used throughout theStandard C++ library.</P><P>Many member functions require an<B><A NAME="operand sequence">operand sequence</A></B> of elements.You can specify such an operand sequence severalways:</P><UL><LI><CODE>ch</CODE> -- one elementwith value <CODE>ch</CODE></LI><LI><CODE>count, ch</CODE> -- a repetition of <CODE>count</CODE> elements eachwith value <CODE>ch</CODE></LI><LI><CODE>ptr</CODE> -- a null-terminated sequence(such as a <A HREF="lib_over.html#C string">C string</A>,for <CODE>Elem</CODE> of type <I>char</I>) beginning at<CODE>ptr</CODE> (which must not be a null pointer),where the terminating element is the value<CODE>value_type()</CODE> and is not part ofthe operand sequence</LI><LI><CODE>ptr, count</CODE> -- a sequence of <CODE>count</CODE> elementsbeginning at <CODE>ptr</CODE> (which must not be a null pointer)</LI><LI><CODE>right</CODE> -- the sequence specified by the<CODE>basic_string</CODE> object <CODE>right</CODE></LI><LI><CODE>right, roff, count</CODE> -- the substring of the<CODE>basic_string</CODE> object <CODE>right</CODE> with up to <CODE>count</CODE>elements (or through the end of the string, whichever comes first)beginning at position <CODE>roff</CODE></LI><LI><CODE>first, last</CODE> -- a sequence of elements delimitedby the iterators <CODE>first</CODE> and <CODE>last</CODE>, in therange <CODE>[first, last)</CODE>, which <I>may</I> overlapthe sequence controlled by the string object whose member functionis being called</LI></UL><P>If a <B><A NAME="position argument">position argument</A></B>(such as <CODE>roff</CODE> above) is beyond the end of the string on acall to a <CODE>basic_string</CODE> member function, the functionreports an<B><A NAME="out-of-range error">out-of-range error</A></B> bythrowing an object of class<A HREF="stdexcep.html#out_of_range"><CODE>out_of_range</CODE></A>.</P><P>If a function is asked to generate a sequence longer than<CODE><A HREF="#basic_string::max_size">max_size</A>()</CODE> elements,the function reports a<B><A NAME="length error">length error</A></B> bythrowing an object of class<A HREF="stdexcep.html#length_error"><CODE>length_error</CODE></A>.</P><P>References, pointers, and iterators that designate elements of thecontrolled sequence can become invalid after any call to a functionthat alters the controlled sequence, or after the first call to thenon-const member functions<CODE><A HREF="#basic_string::at">at</A></CODE>,<CODE><A HREF="#basic_string::begin">begin</A></CODE>,<CODE><A HREF="#basic_string::end">end</A></CODE>,<CODE><A HREF="#basic_string::operator[]">operator[]</A></CODE>,<CODE><A HREF="#basic_string::rbegin">rbegin</A></CODE>, or<CODE><A HREF="#basic_string::rend">rend</A></CODE>.(The idea is to permit multiple strings to share the same representationuntil one string becomes a candidate for change, at which point that stringmakes a private copy of the representation, using a discipline called<B><A NAME="copy on write">copy on write</A></B>.)</P><H3><CODE><A NAME="basic_string::allocator_type">basic_string::allocator_type</A></CODE></H3><PRE>typedef Alloc <B>allocator_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Alloc</CODE>.</P><H3><CODE><A NAME="basic_string::append">basic_string::append</A></CODE></H3><PRE>basic_string& <B>append</B>(const value_type *ptr);basic_string& <B>append</B>(const value_type *ptr, size_type count);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -