📄 string.htm
字号:
<a name="assign5">
Method assign()</a>
Access Public
Classification Modifier
Syntax basic_string& assign(size_type n, charT c);
Parameters <em>n</em> is the number of characters to be assigned.
<em>c</em> is the character to be assigned to the
character sequence of the current object.
Returns This method returns a pointer to the calling object.
</pre>
<h3>Description</h3>
<p>
This assign() method assigns <em>n</em> number of the character <em>c</em> to
the current object's character sequence. The method returns *this.
</p>
<hr>
<pre>
<a name="assign6">
Method assign()</a>
Access Public
Classification Modifier
Syntax template<class InputIterator>
basic_string& assign(InputIterator first,
InputIterator last);
Parameters <em>first</em> points to the beginning of a character
range.
<em>last</em> points to the end of a character range.
Returns This method returns a pointer to the calling object.
</pre>
<h3>Description</h3>
<p>
This assign() method is a template function that assigns a range specified by the input iterators
<em>first</em> and <em>last</em> to the current object's character sequence. The method
return *this. An exception out_of_range is thrown if pos > str.size().
</p>
<hr>
<pre>
<a name="at1">
Method at()</a>
Access Public
Classification Accessor
Syntax const_reference at(size_type pos) const;
Parameters <em>pos</em> is a position in the sequence of the current
object.
Returns This method returns a const reference to the
character at position pos.
</pre>
<h3>Description</h3>
<p>
This at() method returns the const reference to the character at position
<em>pos</em>. This is equivalent to operator[](pos). It requires pos < size().
An exception out_of_range is returned if pos >= size().
</p>
<hr>
<pre>
<a name="at2">
Method at()</a>
Access Public
Classification Accessor
Syntax reference at(size_type pos);
Parameters <em>pos</em> is a position in the character sequence of
the current object.
Returns This method returns a reference to the character at
position pos.
</pre>
<h3>Description</h3>
<p>
This at() method returns the reference to the character at position
<em>pos</em>. This is equivalent to operator[](pos). It requires pos < size().
An exception out_of_range is returned if pos >= size().
</p>
<hr>
<pre>
<a name="basic_string1">
Method basic_string()</a>
Access Public
Classification Constructor
Syntax explicit basic_string(const Allocator& a = Allocator())
Parameter <em>a</em> has a default value Allocator().
Returns None
</pre>
<h3>Description</h3>
<p>
This is the default constructor. This explicit constructor constructs a basic_string
object with a single argument. This means the constructor
is only invoked when the argument type matches the
parameter type exactly. The compiler will not perform any type conversion. The
Allocator object has a default value.<br>
<br>
After construction:
</p>
<pre>
data() returns a non-null pointer; 0 can be added to it.
size() returns 0.
capacity() returns an unspecified value.
</pre>
<hr>
<pre>
<a name="basic_string2">
Method basic_string()</a>
Access Public
Classification Constructor
Syntax basic_string(const basic_string& str,
size_type pos = 0,
size_type n = npos,
const Allocator& a = Allocator())
Parameters <em>str</em> is a basic_string object in which the current
object is initialized.
<em>pos</em> is a position in the character sequence of str.
<em>n</em> is the length of the character sequence of str
to be assigned to the new object.
<em>a</em> has a default value Allocator().
Returns None
</pre>
<h3>Description</h3>
<p>
This constructor constructs a basic_string object and initializes the basic_string
object with another basic_string object <em>str</em>. <em>pos</em> has a default
value of 0. <em>pos</em> has to be
less than or equal to str.size(). <em>n</em> has a default value of npos.
npos is initialized to the largest possible value. <em>pos</em> and <em>n</em>
determines the character sequence to be copied into the new string object. The
length of the sequence is the smaller of <em>n</em> and str.size() - <em>pos</em>.
The allocator object has a default value Allocator(). This constructor throws an
exception out-of-range is <em>pos</em> > str.size().<br>
<br>
After construction:
</p>
<pre>
data() returns a pointer that points to the first
element of an allocated copy of strlength
consecutive elements of the string controlled by
str beginning at position pos.
size() returns strlength which is the smaller of
n and str.size() - pos.
capacity() returns a value at least as large as
size().
get_allocator() returns str.get_allocator().
</pre>
<hr>
<pre>
<a name="basic_string3">
Method basic_string()</a>
Access Public
Classification Constructor
Syntax basic_string(const charT* s,
size_type n,
const Allocator& a = Allocator());
Parameters <em>s</em> points to the character array to be copied
to the new object.
<em>n</em> is the length of the character sequence.
<em>a</em> has a default value Allocator().
Returns None
</pre>
<h3>Description</h3>
<p>
This constructor constructs a basic_string object and initializes the
basic_string object with the array of charT pointed to by <em>s</em>, the
first element in the array. <em>s</em> is not be a null pointer. The length
of the string is determined by <em>n</em>. <em>n</em> is
less than npos. The allocator object has a default value Allocator(). This
constructor throws an exception out_of_range if n == npos.<br>
<br>
After construction:
</p>
<pre>
data() returns a pointer that points to the first
element of an allocated copy of the array whose
first element is pointed to by s.
size() returns n.
capacity() returns a value at least as large as
size().
</pre>
<hr>
<pre>
<a name="basic_string4">
Method basic_string()</a>
Access Public
Classification Constructor
Syntax basic_string(const charT* s,
const Allocator& a = Allocator());
Parameters <em>s</em> points to the character array to be copied
to the new object.
<em>a</em> has a default value Allocator().
Returns None
</pre>
<h3>Description</h3>
<p>
This constructor constructs a basic_string object and initializes the basic_string
object with the array of charT pointed to by <em>s</em>, the first element in the
array. <em>s</em> is not be a null pointer. The length of the string is determined
by traits::length(s). The allocator object has a default value Allocator().<br>
<br>
After construction:
</p>
<pre>
data() returns a pointer that points to the first
element of an allocated whose first element is pointed
to by s.
size() returns traits::length(s).
capacity() returns a value at least as large as size().
</pre>
<hr>
<pre>
<a name="basic_string5">
Method basic_string()</a>
Access Public
Classification Constructor
Syntax basic_string(size_type n,
charT c,
const Allocator& a = Allocator());
Parameters <em>n</em> is the number of characters to be copied to the
new object.
<em>c</em> is the character to be copied.
<em>a</em> has a default value Allocator().
Returns None
</pre>
<h3>Description</h3>
<p>
This constructor constructs a basic_string object and initializes the
basic_string object with the charT <em>c</em> repeated <em>n</em> times.
<em>n</em> is less than npos. The allocator object has a default value
Allocator(). This constructor throws an exception length_error if n == npos.<br>
<br>
After construction:
</p>
<pre>
data() returns a pointer that points to the first
element of an allocated copy of the array whose
first element is pointed to by str.data().
size() returns str.size().
capacity() returns a value at least as large as
size().
</pre>
<hr>
<pre>
<a name="basic_string6">
Method basic_string()</a>
Access Public
Classification Constructor
Syntax template <class InputIterator>
basic_string(InputIterator begin, InputIterator end,
const Allocator& a = Allocator());
Parameters <em>begin</em> points to the beginning of a character
range.
<em>end</em> points to the end of a character range.
<em>a</em> has a default value Allocator().
Returns None
</pre>
<h3>Description</h3>
<p>
A template constructor that constructs a basic_string object and initializes
the basic_string object with the values determined by the range [begin, end).
The length of the string is determined by the distance between <em>begin</em> and <em>end</em>.
The allocator object has a default value Allocator().<br>
<br>
After construction:
</p>
<pre>
data() returns a pointer that points to the first
element of an allocated copy of the elements in
the range [begin, end).
size() returns the distance between begin and end.
capacity() returns a value at least as large as
size().
</pre>
<hr>
<pre>
<a name="~basic_string">
Method basic_string()</a>
Access Public
Classification Destructor
Syntax ~basic_string();
Parameters None
Returns None
</pre>
<h3>Description</h3>
<p>
The ~basic_string() destroys the basic_string object.
</p>
<hr>
<pre>
<a name="begin1">
Method begin()</a>
Access Public
Classification Accessor
Syntax iterator begin();
Parameters None
Returns This method returns an iterator that points to the
first element of the current object's character
sequence.
</pre>
<h3>Description</h3>
<p>
This begin() method returns an iterator that points to the first element of the basic_string
object's character sequence.
</p>
<hr>
<pre>
<a name="begin2">
Method begin()</a>
Access Public
Classification Accessor
Syntax const_iterator begin() const;
Parameters None
Returns This method returns a const iterator that points
to the first element of the current object's
character sequence.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -