basic_string Class Template Reference
[ContainersSequences]

Inheritance diagram for basic_string:

Inheritance graph
List of all members.

Detailed Description

template<typename _CharT, typename _Traits, typename _Alloc>
class std::basic_string< _CharT, _Traits, _Alloc >

Meets the requirements of a container, a reversible container, and a sequence. Of the optional sequence requirements, only push_back, at, and array access are supported.

Todo:
Doc me! See docs/doxygen/TODO and http://gcc.gnu.org/ml/libstdc++/2002-02/msg00003.html for more.

Definition at line 110 of file basic_string.h.

Public Types

Public Member Functions

Static Public Attributes


Constructor & Destructor Documentation

basic_string  )  [inline]
 

Default constructor creates an empty string.

Definition at line 2041 of file basic_string.h.

Referenced by basic_string< char >::substr().

basic_string const _Alloc &  __a  )  [explicit]
 

Construct an empty string using allocator a.

Definition at line 190 of file basic_string.tcc.

basic_string const basic_string< _CharT, _Traits, _Alloc > &  __str  ) 
 

Construct string with copy of value of str.

Parameters:
str Source string.

Definition at line 182 of file basic_string.tcc.

basic_string const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos,
size_type  __n = npos
 

Construct string as copy of a substring.

Parameters:
str Source string.
pos Index of first character to copy from.
n Number of characters to copy (default remainder).

Definition at line 196 of file basic_string.tcc.

basic_string const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos,
size_type  __n,
const _Alloc &  __a
 

Construct string as copy of a substring.

Parameters:
str Source string.
pos Index of first character to copy from.
n Number of characters to copy.
a Allocator to use.

Definition at line 206 of file basic_string.tcc.

basic_string const _CharT *  __s,
size_type  __n,
const _Alloc &  __a = _Alloc()
 

Construct string initialized by a character array.

Parameters:
s Source character array.
n Number of characters to copy.
a Allocator to use (default is default allocator).
NB: s must have at least n characters, '' has no special meaning.

Definition at line 218 of file basic_string.tcc.

basic_string const _CharT *  __s,
const _Alloc &  __a = _Alloc()
 

Construct string as copy of a C string.

Parameters:
s Source C string.
a Allocator to use (default is default allocator).

Definition at line 225 of file basic_string.tcc.

basic_string size_type  __n,
_CharT  __c,
const _Alloc &  __a = _Alloc()
 

Construct string as multiple characters.

Parameters:
n Number of characters.
c Character to use.
a Allocator to use (default is default allocator).

Definition at line 232 of file basic_string.tcc.

basic_string _InputIterator  __beg,
_InputIterator  __end,
const _Alloc &  __a = _Alloc()
 

Construct string as copy of a range.

Parameters:
beg Start of range.
end End of range.
a Allocator to use (default is default allocator).

Definition at line 240 of file basic_string.tcc.

~basic_string  )  [inline]
 

Destroy the string instance.

Definition at line 471 of file basic_string.h.


Member Function Documentation

basic_string& append _InputIterator  __first,
_InputIterator  __last
[inline]
 

Append a range of characters.

Parameters:
first Iterator referencing the first character to append.
last Iterator marking the end of the range.
Returns:
Reference to this string.
Appends characters in the range [first,last) to this string.

Definition at line 837 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc > & append size_type  __n,
_CharT  __c
 

Append multiple characters.

Parameters:
n The number of characters to append.
c The character to use.
Returns:
Reference to this string.
Appends n copies of c to this string.

Definition at line 285 of file basic_string.tcc.

References basic_string::reserve(), and basic_string::size().

basic_string& append const _CharT *  __s  )  [inline]
 

Append a C string.

Parameters:
s The C string to append.
Returns:
Reference to this string.

Definition at line 810 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc > & append const _CharT *  __s,
size_type  __n
 

Append a C substring.

Parameters:
s The C string to append.
n The number of characters to append.
Returns:
Reference to this string.

Definition at line 302 of file basic_string.tcc.

References basic_string::reserve(), and basic_string::size().

basic_string< _CharT, _Traits, _Alloc > & append const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos,
size_type  __n
 

Append a substring.

Parameters:
str The string to append.
pos Index of the first character of str to append.
n The number of characters to append.
Returns:
Reference to this string.
Exceptions:
std::out_of_range if pos is not a valid index.
This function appends n characters from str starting at pos to this string. If n is is larger than the number of available characters in str, the remainder of str is appended.

Definition at line 346 of file basic_string.tcc.

References basic_string::reserve(), and basic_string::size().

basic_string< _CharT, _Traits, _Alloc > & append const basic_string< _CharT, _Traits, _Alloc > &  __str  ) 
 

Append a string to this string.

Parameters:
str The string to append.
Returns:
Reference to this string.

Definition at line 329 of file basic_string.tcc.

References basic_string::reserve(), and basic_string::size().

Referenced by basic_string< char >::append(), collate::do_transform(), std::operator+(), basic_string< char >::operator+=(), std::operator>>(), and basic_string::resize().

basic_string& assign _InputIterator  __first,
_InputIterator  __last
[inline]
 

Set value to a range of characters.

Parameters:
first Iterator referencing the first character to append.
last Iterator marking the end of the range.
Returns:
Reference to this string.
Sets value of string to characters in the range [first,last).

Definition at line 932 of file basic_string.h.

basic_string& assign size_type  __n,
_CharT  __c
[inline]
 

Set value to multiple characters.

Parameters:
n Length of the resulting string.
c The character to use.
Returns:
Reference to this string.
This function sets the value of this string to n copies of character c.

Definition at line 919 of file basic_string.h.

basic_string& assign const _CharT *  __s  )  [inline]
 

Set value to contents of a C string.

Parameters:
s The C string to use.
Returns:
Reference to this string.
This function sets the value of this string to the value of s. The data is copied, so there is no dependence on s once the function returns.

Definition at line 903 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc > & assign const _CharT *  __s,
size_type  __n
 

Set value to a C substring.

Parameters:
s The C string to use.
n Number of characters to use.
Returns:
Reference to this string.
This function sets the value of this string to the first n characters of s. If n is is larger than the number of available characters in s, the remainder of s is used.

Definition at line 263 of file basic_string.tcc.

basic_string& assign const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos,
size_type  __n
[inline]
 

Set value to a substring of a string.

Parameters:
str The string to use.
pos Index of the first character of str.
n Number of characters to use.
Returns:
Reference to this string.
Exceptions:
std::out_of_range if pos is not a valid index.
This function sets this string to the substring of str consisting of n characters at pos. If n is is larger than the number of available characters in str, the remainder of str is used.

Definition at line 875 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc > & assign const basic_string< _CharT, _Traits, _Alloc > &  __str  ) 
 

Set value to contents of another string.

Parameters:
str Source string to use.
Returns:
Reference to this string.

Definition at line 247 of file basic_string.tcc.

References basic_string::_M_rep(), and basic_string::get_allocator().

Referenced by basic_string< char >::assign(), money_get::do_get(), basic_string< char >::operator=(), basic_stringbuf::overflow(), basic_stringbuf::setbuf(), and basic_stringbuf::str().

reference at size_type  __n  )  [inline]
 

Provides access to the data contained in the string.

Parameters:
n The index of the character to access.
Returns:
Read/write reference to the character.
Exceptions:
std::out_of_range If n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. Success results in unsharing the string.

Definition at line 733 of file basic_string.h.

const_reference at size_type  __n  )  const [inline]
 

Provides access to the data contained in the string.

Parameters:
n The index of the character to access.
Returns:
Read-only (const) reference to the character.
Exceptions:
std::out_of_range If n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails.

Definition at line 714 of file basic_string.h.

const_iterator begin  )  const [inline]
 

Returns a read-only (constant) iterator that points to the first character in the string.

Definition at line 521 of file basic_string.h.

iterator begin  )  [inline]
 

Returns a read/write iterator that points to the first character in the string. Unshares the string.

Definition at line 510 of file basic_string.h.

const _CharT* c_str  )  const [inline]
 

Return const pointer to null-terminated contents.

This is a handle to internal data. Do not modify or dire things may happen.

Definition at line 1508 of file basic_string.h.

Referenced by collate::do_compare(), money_get::do_get(), and collate::do_transform().

size_type capacity  )  const [inline]
 

Returns the total number of characters that the string can hold before needing to allocate more memory.

Definition at line 630 of file basic_string.h.

Referenced by basic_stringbuf::overflow().

void clear  )  [inline]
 

Erases the string, making it empty.

Definition at line 657 of file basic_string.h.

int compare size_type  __pos,
size_type  __n1,
const _CharT *  __s,
size_type  __n2
const
 

Compare substring against a character array.

Parameters:
pos1 Index of first character of substring.
n1 Number of characters in substring.
s character array to compare against.
n2 Number of characters of s.
Returns:
Integer < 0, 0, or > 0.
Form the substring of this string from the n1 characters starting at pos1. Form a string from the first n2 characters of s. Returns an integer < 0 if this substring is ordered before the string from s, 0 if their values are equivalent, or > 0 if this substring is ordered after the string from s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and n2. The function then compares the two strings by calling traits::compare(substring.data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.

NB: s must have at least n2 characters, '' has no special meaning.

Definition at line 949 of file basic_string.tcc.

References std::min().

int compare size_type  __pos,
size_type  __n1,
const _CharT *  __s
const
 

Compare substring to a C string.

Parameters:
pos Index of first character of substring.
n1 Number of characters in substring.
s C string to compare against.
Returns:
Integer < 0, 0, or > 0.
Form the substring of this string from the n1 characters starting at pos. Returns an integer < 0 if the substring is ordered before s, 0 if their values are equivalent, or > 0 if the substring is ordered after s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and the length of a string constructed from s. The function then compares the two string by calling traits::compare(substring.data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.

Definition at line 933 of file basic_string.tcc.

References std::min().

int compare const _CharT *  __s  )  const
 

Compare to a C string.

Parameters:
s C string to compare against.
Returns:
Integer < 0, 0, or > 0.
Returns an integer < 0 if this string is ordered before s, 0 if their values are equivalent, or > 0 if this string is ordered after s. Determines the effective length rlen of the strings to compare as the smallest of size() and the length of a string constructed from s. The function then compares the two strings by calling traits::compare(data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.

Definition at line 918 of file basic_string.tcc.

References std::min(), and basic_string::size().

int compare size_type  __pos1,
size_type  __n1,
const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos2,
size_type  __n2
const
 

Compare substring to a substring.

Parameters:
pos1 Index of first character of substring.
n1 Number of characters in substring.
str String to compare against.
pos2 Index of first character of substring of str.
n2 Number of characters in substring of str.
Returns:
Integer < 0, 0, or > 0.
Form the substring of this string from the n1 characters starting at pos1. Form the substring of str from the n2 characters starting at pos2. Returns an integer < 0 if this substring is ordered before the substring of str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of str. Determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. The function then compares the two strings by calling traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.

Definition at line 900 of file basic_string.tcc.

References basic_string::_M_check(), basic_string::_M_limit(), basic_string::data(), and std::min().

int compare size_type  __pos,
size_type  __n,
const basic_string< _CharT, _Traits, _Alloc > &  __str
const
 

Compare substring to a string.

Parameters:
pos Index of first character of substring.
n Number of characters in substring.
str String to compare against.
Returns:
Integer < 0, 0, or > 0.
Form the substring of this string from the n characters starting at pos. Returns an integer < 0 if the substring is ordered before str, 0 if their values are equivalent, or > 0 if the substring is ordered after str. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and str.size(). The function then compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.

Definition at line 885 of file basic_string.tcc.

References basic_string::data(), std::min(), and basic_string::size().

int compare const basic_string< _CharT, _Traits, _Alloc > &  __str  )  const [inline]
 

Compare to a string.

Parameters:
str String to compare against.
Returns:
Integer < 0, 0, or > 0.
Returns an integer < 0 if this string is ordered before str, 0 if their values are equivalent, or > 0 if this string is ordered after str. Determines the effective length rlen of the strings to compare as the smallest of size() and str.size(). The function then compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.

Definition at line 1915 of file basic_string.h.

Referenced by std::operator!=(), std::operator<(), std::operator<=(), std::operator==(), std::operator>(), and std::operator>=().

basic_string< _CharT, _Traits, _Alloc >::size_type copy _CharT *  __s,
size_type  __n,
size_type  __pos = 0
const
 

Copy substring into C string.

Parameters:
s C string to copy value into.
n Number of characters to copy.
pos Index of first character to copy.
Returns:
Number of characters actually copied
Exceptions:
std::out_of_range If pos > size().
Copies up to n characters starting at pos into the C string s. If pos is greater than size(), out_of_range is thrown.

Definition at line 696 of file basic_string.tcc.

const _CharT* data  )  const [inline]
 

Return const pointer to contents.

This is a handle to internal data. Do not modify or dire things may happen.

Definition at line 1518 of file basic_string.h.

Referenced by basic_string::compare(), basic_string< char >::compare(), collate::do_compare(), money_get::do_get(), collate::do_transform(), basic_string< char >::find(), basic_string< char >::find_first_not_of(), basic_string< char >::find_first_of(), basic_string< char >::find_last_not_of(), basic_string< char >::find_last_of(), locale::operator()(), basic_stringbuf::overflow(), basic_string< char >::rfind(), and basic_stringbuf::str().

bool empty  )  const [inline]
 

Returns true if the string is empty. Equivalent to *this == "".

Definition at line 664 of file basic_string.h.

Referenced by std::operator>>().

const_iterator end  )  const [inline]
 

Returns a read-only (constant) iterator that points one past the last character in the string.

Definition at line 540 of file basic_string.h.

iterator end  )  [inline]
 

Returns a read/write iterator that points one past the last character in the string. Unshares the string.

Definition at line 529 of file basic_string.h.

iterator erase iterator  __first,
iterator  __last
[inline]
 

Remove a range of characters.

Parameters:
first Iterator referencing the first character to remove.
last Iterator referencing the end of the range.
Returns:
Iterator referencing location of first after removal.
Removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown.

Definition at line 1142 of file basic_string.h.

iterator erase iterator  __position  )  [inline]
 

Remove one character.

Parameters:
position Iterator referencing the character to remove.
Returns:
iterator referencing same location after removal.
Removes the character at position from this string. The value of the string doesn't change if an error is thrown.

Definition at line 1122 of file basic_string.h.

basic_string& erase size_type  __pos = 0,
size_type  __n = npos
[inline]
 

Remove characters.

Parameters:
pos Index of first character to remove (default 0).
n Number of characters to remove (default remainder).
Returns:
Reference to this string.
Exceptions:
std::out_of_range If pos is beyond the end of this string.
Removes n characters from this string starting at pos. The length of the string is reduced by n. If there are < n characters to remove, the remainder of the string is truncated. If p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1106 of file basic_string.h.

Referenced by std::getline(), std::operator>>(), and basic_string::resize().

basic_string< _CharT, _Traits, _Alloc >::size_type find _CharT  __c,
size_type  __pos = 0
const
 

Find position of a character.

Parameters:
c Character to locate.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches forward for c within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 729 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type find const _CharT *  __s,
size_type  __pos = 0
const [inline]
 

Find position of a C string.

Parameters:
s C string to locate.
pos Index of character to search from (default 0).
Returns:
Index of start of first occurrence.
Starting from pos, searches forward for the value of s within this string. If found, returns the index where it begins. If not found, returns npos.

Definition at line 1567 of file basic_string.h.

size_type find const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos = 0
const [inline]
 

Find position of a string.

Parameters:
str String to locate.
pos Index of character to search from (default 0).
Returns:
Index of start of first occurrence.
Starting from pos, searches forward for value of str within this string. If found, returns the index where it begins. If not found, returns npos.

Definition at line 1553 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc >::size_type find const _CharT *  __s,
size_type  __pos,
size_type  __n
const
 

Find position of a C substring.

Parameters:
s C string to locate.
pos Index of character to search from.
n Number of characters from s to search for.
Returns:
Index of start of first occurrence.
Starting from pos, searches forward for the first n characters in s within this string. If found, returns the index where it begins. If not found, returns npos.

Definition at line 710 of file basic_string.tcc.

References basic_string::npos, std::search(), and basic_string::size().

Referenced by basic_string< char >::find(), and basic_string< char >::find_first_of().

basic_string< _CharT, _Traits, _Alloc >::size_type find_first_not_of _CharT  __c,
size_type  __pos = 0
const
 

Find position of a different character.

Parameters:
c Character to avoid.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches forward for a character other than c within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 833 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type find_first_not_of const _CharT *  __s,
size_type  __pos = 0
const [inline]
 

Find position of a character not in C string.

Parameters:
s C string containing characters to avoid.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches forward for a character not contained in s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1806 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc >::size_type find_first_not_of const _CharT *  __s,
size_type  __pos,
size_type  __n
const
 

Find position of a character not in C substring.

Parameters:
s C string containing characters to avoid.
pos Index of character to search from (default 0).
n Number of characters from s to consider.
Returns:
Index of first occurrence.
Starting from pos, searches forward for a character not contained in the first n characters of s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 821 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type find_first_not_of const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos = 0
const [inline]
 

Find position of a character not in string.

Parameters:
str String containing characters to avoid.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches forward for a character not contained in str within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1777 of file basic_string.h.

Referenced by basic_string< char >::find_first_not_of().

size_type find_first_of _CharT  __c,
size_type  __pos = 0
const [inline]
 

Find position of a character.

Parameters:
c Character to locate.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches forward for the character c within this string. If found, returns the index where it was found. If not found, returns npos.

Note: equivalent to find(c, pos).

Definition at line 1702 of file basic_string.h.

size_type find_first_of const _CharT *  __s,
size_type  __pos = 0
const [inline]
 

Find position of a character of C string.

Parameters:
s String containing characters to locate.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches forward for one of the characters of s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1683 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc >::size_type find_first_of const _CharT *  __s,
size_type  __pos,
size_type  __n
const
 

Find position of a character of C substring.

Parameters:
s String containing characters to locate.
pos Index of character to search from (default 0).
n Number of characters from s to search for.
Returns:
Index of first occurrence.
Starting from pos, searches forward for one of the first n characters of s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 785 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type find_first_of const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos = 0
const [inline]
 

Find position of a character of string.

Parameters:
str String containing characters to locate.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches forward for one of the characters of str within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1655 of file basic_string.h.

Referenced by basic_string< char >::find_first_of().

basic_string< _CharT, _Traits, _Alloc >::size_type find_last_not_of _CharT  __c,
size_type  __pos = npos
const
 

Find last position of a different character.

Parameters:
c Character to avoid.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches backward for a character other than c within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 865 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type find_last_not_of const _CharT *  __s,
size_type  __pos = npos
const [inline]
 

Find position of a character not in C string.

Parameters:
s C string containing characters to avoid.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches backward for a character not contained in s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1865 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc >::size_type find_last_not_of const _CharT *  __s,
size_type  __pos,
size_type  __n
const
 

Find last position of a character not in C substring.

Parameters:
s C string containing characters to avoid.
pos Index of character to search from (default 0).
n Number of characters from s to consider.
Returns:
Index of first occurrence.
Starting from pos, searches backward for a character not contained in the first n characters of s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 844 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type find_last_not_of const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos = npos
const [inline]
 

Find last position of a character not in string.

Parameters:
str String containing characters to avoid.
pos Index of character to search from (default 0).
Returns:
Index of first occurrence.
Starting from pos, searches backward for a character not contained in str within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1836 of file basic_string.h.

Referenced by basic_string< char >::find_last_not_of().

size_type find_last_of _CharT  __c,
size_type  __pos = npos
const [inline]
 

Find last position of a character.

Parameters:
c Character to locate.
pos Index of character to search back from (default 0).
Returns:
Index of last occurrence.
Starting from pos, searches backward for c within this string. If found, returns the index where it was found. If not found, returns npos.

Note: equivalent to rfind(c, pos).

Definition at line 1763 of file basic_string.h.

size_type find_last_of const _CharT *  __s,
size_type  __pos = npos
const [inline]
 

Find last position of a character of C string.

Parameters:
s C string containing characters to locate.
pos Index of character to search back from (default end).
Returns:
Index of last occurrence.
Starting from pos, searches backward for one of the characters of s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1744 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc >::size_type find_last_of const _CharT *  __s,
size_type  __pos,
size_type  __n
const
 

Find last position of a character of C substring.

Parameters:
s C string containing characters to locate.
pos Index of character to search back from (default end).
n Number of characters from s to search for.
Returns:
Index of last occurrence.
Starting from pos, searches backward for one of the first n characters of s within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 800 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type find_last_of const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos = npos
const [inline]
 

Find last position of a character of string.

Parameters:
str String containing characters to locate.
pos Index of character to search back from (default end).
Returns:
Index of last occurrence.
Starting from pos, searches backward for one of the characters of str within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 1716 of file basic_string.h.

Referenced by basic_string< char >::find_last_of().

allocator_type get_allocator  )  const [inline]
 

Return copy of allocator used to construct this string.

Definition at line 1525 of file basic_string.h.

Referenced by basic_string::assign(), basic_string::reserve(), and basic_string::swap().

iterator insert iterator  __p,
_CharT  __c
[inline]
 

Insert one character.

Parameters:
p Iterator referencing position in string to insert at.
c The character to insert.
Returns:
Iterator referencing newly inserted char.
Exceptions:
std::length_error If new length exceeds max_size().
Inserts character c at position referenced by p. If adding character causes the length to exceed max_size(), length_error is thrown. If p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1082 of file basic_string.h.

basic_string& insert size_type  __pos,
size_type  __n,
_CharT  __c
[inline]
 

Insert multiple characters.

Parameters:
pos Index in string to insert at.
n Number of characters to insert
c The character to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
std::out_of_range If pos is beyond the end of this string.
Inserts n copies of character c starting at index pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If pos > length(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1065 of file basic_string.h.

basic_string& insert size_type  __pos,
const _CharT *  __s
[inline]
 

Insert a C string.

Parameters:
pos Iterator referencing location in string to insert at.
s The C string to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
std::out_of_range If pos is beyond the end of this string.
Inserts the first n characters of s starting at pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1042 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc > & insert size_type  __pos,
const _CharT *  __s,
size_type  __n
 

Insert a C substring.

Parameters:
pos Iterator referencing location in string to insert at.
s The C string to insert.
n The number of characters to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
std::out_of_range If pos is beyond the end of this string.
Inserts the first n characters of s starting at pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 364 of file basic_string.tcc.

basic_string& insert size_type  __pos1,
const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos2,
size_type  __n
[inline]
 

Insert a substring.

Parameters:
pos1 Iterator referencing location in string to insert at.
str The string to insert.
pos2 Start of characters in str to insert.
n Number of characters to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
std::out_of_range If pos1 > size() or pos2 > str.size().
Starting at pos1, insert n character of str beginning with pos2. If adding characters causes the length to exceed max_size(), length_error is thrown. If pos1 is beyond the end of this string or pos2 is beyond the end of str, out_of_range is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1001 of file basic_string.h.

basic_string& insert size_type  __pos1,
const basic_string< _CharT, _Traits, _Alloc > &  __str
[inline]
 

Insert value of a string.

Parameters:
pos1 Iterator referencing location in string to insert at.
str The string to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
Inserts value of str starting at pos1. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 979 of file basic_string.h.

void insert iterator  __p,
_InputIterator  __beg,
_InputIterator  __end
[inline]
 

Insert a range of characters.

Parameters:
p Iterator referencing location in string to insert at.
beg Start of range.
end End of range.
Exceptions:
std::length_error If new length exceeds max_size().
Inserts characters in range [beg,end). If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 964 of file basic_string.h.

void insert iterator  __p,
size_type  __n,
_CharT  __c
[inline]
 

Insert multiple characters.

Parameters:
p Iterator referencing location in string to insert at.
n Number of characters to insert
c The character to insert.
Exceptions:
std::length_error If new length exceeds max_size().
Inserts n copies of character c starting at the position referenced by iterator p. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 948 of file basic_string.h.

Referenced by basic_string< char >::insert().

size_type length  )  const [inline]
 

null-termination.

Definition at line 590 of file basic_string.h.

Referenced by collate::do_compare(), collate::do_transform(), and locale::operator()().

size_type max_size  )  const [inline]
 

Returns the size() of the largest possible string.

Definition at line 595 of file basic_string.h.

Referenced by std::getline(), std::operator>>(), and basic_stringbuf::overflow().

basic_string& operator+= _CharT  __c  )  [inline]
 

Append a character.

Parameters:
s The character to append.
Returns:
Reference to this string.

Definition at line 766 of file basic_string.h.

basic_string& operator+= const _CharT *  __s  )  [inline]
 

Append a C string.

Parameters:
s The C string to append.
Returns:
Reference to this string.

Definition at line 757 of file basic_string.h.

basic_string& operator+= const basic_string< _CharT, _Traits, _Alloc > &  __str  )  [inline]
 

Append a string to this string.

Parameters:
str The string to append.
Returns:
Reference to this string.

Definition at line 748 of file basic_string.h.

basic_string& operator= _CharT  __c  )  [inline]
 

Set value to string of length 1.

Parameters:
c Source character.
Assigning to a character makes this string length 1 and (*this)[0] == c.

Definition at line 498 of file basic_string.h.

basic_string& operator= const _CharT *  __s  )  [inline]
 

Copy contents of s into this string.

Parameters:
s Source null-terminated string.

Definition at line 487 of file basic_string.h.

basic_string& operator= const basic_string< _CharT, _Traits, _Alloc > &  __str  )  [inline]
 

Assign the value of str to this string.

Parameters:
str Source string.

Definition at line 479 of file basic_string.h.

reference operator[] size_type  __pos  )  [inline]
 

Subscript access to the data contained in the string.

Parameters:
n The index of the character to access.
Returns:
Read/write reference to the character.
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) Unshares the string.

Definition at line 696 of file basic_string.h.

const_reference operator[] size_type  __pos  )  const [inline]
 

Subscript access to the data contained in the string.

Parameters:
n The index of the character to access.
Returns:
Read-only (constant) reference to the character.
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().)

Definition at line 679 of file basic_string.h.

void push_back _CharT  __c  )  [inline]
 

Append a single character.

Parameters:
c Character to append.

Definition at line 845 of file basic_string.h.

Referenced by collate::do_transform(), basic_string< char >::operator+=(), and std::operator>>().

const_reverse_iterator rbegin  )  const [inline]
 

Returns a read-only (constant) reverse iterator that points to the last character in the string. Iteration is done in reverse element order.

Definition at line 558 of file basic_string.h.

reverse_iterator rbegin  )  [inline]
 

Returns a read/write reverse iterator that points to the last character in the string. Iteration is done in reverse element order. Unshares the string.

Definition at line 549 of file basic_string.h.

const_reverse_iterator rend  )  const [inline]
 

Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order.

Definition at line 576 of file basic_string.h.

reverse_iterator rend  )  [inline]
 

Returns a read/write reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order. Unshares the string.

Definition at line 567 of file basic_string.h.

basic_string& replace iterator  __i1,
iterator  __i2,
_InputIterator  __k1,
_InputIterator  __k2
[inline]
 

Replace range of characters with range.

Parameters:
i1 Iterator referencing start of range to replace.
i2 Iterator referencing end of range to replace.
k1 Iterator referencing start of range to insert.
k2 Iterator referencing end of range to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
Removes the characters in the range [i1,i2). In place, characters in the range [k1,k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1358 of file basic_string.h.

basic_string& replace iterator  __i1,
iterator  __i2,
size_type  __n,
_CharT  __c
[inline]
 

Replace range of characters with multiple characters.

Parameters:
i1 Iterator referencing start of range to replace.
i2 Iterator referencing end of range to replace.
n Number of characters to insert.
c Character to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
Removes the characters in the range [i1,i2). In place, n copies of c are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1335 of file basic_string.h.

basic_string& replace iterator  __i1,
iterator  __i2,
const _CharT *  __s
[inline]
 

Replace range of characters with C string.

Parameters:
i1 Iterator referencing start of range to replace.
i2 Iterator referencing end of range to replace.
s C string value to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
Removes the characters in the range [i1,i2). In place, the characters of s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1314 of file basic_string.h.

basic_string& replace iterator  __i1,
iterator  __i2,
const _CharT *  __s,
size_type  __n
[inline]
 

Replace range of characters with C substring.

Parameters:
i1 Iterator referencing start of range to replace.
i2 Iterator referencing end of range to replace.
s C string value to insert.
n Number of characters from s to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
Removes the characters in the range [i1,i2). In place, the first n characters of s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1293 of file basic_string.h.

basic_string& replace iterator  __i1,
iterator  __i2,
const basic_string< _CharT, _Traits, _Alloc > &  __str
[inline]
 

Replace range of characters with string.

Parameters:
i1 Iterator referencing start of range to replace.
i2 Iterator referencing end of range to replace.
str String value to insert.
Returns:
Reference to this string.
Exceptions:
std::length_error If new length exceeds max_size().
Removes the characters in the range [i1,i2). In place, the value of str is inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1275 of file basic_string.h.

basic_string& replace size_type  __pos,
size_type  __n1,
size_type  __n2,
_CharT  __c
[inline]
 

Replace characters with multiple characters.

Parameters:
pos Index of first character to replace.
n1 Number of characters to be replaced.
n2 Number of characters to insert.
c Character to insert.
Returns:
Reference to this string.
Exceptions:
std::out_of_range If pos > size().
std::length_error If new length exceeds max_size().
Removes the characters in the range [pos,pos + n1) from this string. In place, n2 copies of c are inserted. If pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1257 of file basic_string.h.

basic_string& replace size_type  __pos,
size_type  __n1,
const _CharT *  __s
[inline]
 

Replace characters with value of a C string.

Parameters:
pos Index of first character to replace.
n1 Number of characters to be replaced.
str C string to insert.
Returns:
Reference to this string.
Exceptions:
std::out_of_range If pos > size().
std::length_error If new length exceeds max_size().
Removes the characters in the range [pos,pos + n1) from this string. In place, the first n characters of str are inserted. If pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1234 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc > & replace size_type  __pos,
size_type  __n1,
const _CharT *  __s,
size_type  __n2
 

Replace characters with value of a C substring.

Parameters:
pos Index of first character to replace.
n1 Number of characters to be replaced.
str C string to insert.
n2 Number of characters from str to use.
Returns:
Reference to this string.
Exceptions:
std::out_of_range If pos1 > size().
std::length_error If new length exceeds max_size().
Removes the characters in the range [pos,pos + n1) from this string. In place, the first n2 characters of str are inserted, or all of str if n2 is too large. If pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 395 of file basic_string.tcc.

References basic_string::_M_data().

basic_string& replace size_type  __pos1,
size_type  __n1,
const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos2,
size_type  __n2
[inline]
 

Replace characters with value from another string.

Parameters:
pos1 Index of first character to replace.
n1 Number of characters to be replaced.
str String to insert.
pos2 Index of first character of str to use.
n2 Number of characters from str to use.
Returns:
Reference to this string.
Exceptions:
std::out_of_range If pos1 > size() or pos2 > str.size().
std::length_error If new length exceeds max_size().
Removes the characters in the range [pos1,pos1 + n) from this string. In place, the value of str is inserted. If pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1191 of file basic_string.h.

basic_string& replace size_type  __pos,
size_type  __n,
const basic_string< _CharT, _Traits, _Alloc > &  __str
[inline]
 

Replace characters with value from another string.

Parameters:
pos Index of first character to replace.
n Number of characters to be replaced.
str String to insert.
Returns:
Reference to this string.
Exceptions:
std::out_of_range If pos is beyond the end of this string.
std::length_error If new length exceeds max_size().
Removes the characters in the range [pos,pos+n) from this string. In place, the value of str is inserted. If pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

Definition at line 1169 of file basic_string.h.

Referenced by basic_string< char >::append(), basic_string< char >::assign(), basic_string< char >::insert(), and basic_string< char >::replace().

void reserve size_type  __res_arg = 0  ) 
 

Attempt to preallocate enough memory for specified number of characters.

Parameters:
n Number of characters required.
Exceptions:
std::length_error If n exceeds max_size().
This function attempts to reserve enough memory for the string to hold the specified number of characters. If the number requested is more than max_size(), length_error is thrown.

The advantage of this function is that if optimal code is a necessity and the user can determine the string length that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of string data.

Definition at line 483 of file basic_string.tcc.

References basic_string::get_allocator(), and basic_string::size().

Referenced by basic_string::append(), std::operator>>(), basic_stringbuf::overflow(), and basic_string< char >::push_back().

void resize size_type  __n  )  [inline]
 

Resizes the string to the specified number of characters.

Parameters:
n Number of characters the string should contain.
This function will resize the string to the specified length. If the new size is smaller than the string's current size the string is truncated, otherwise the string is extended and new characters are default-constructed. For basic types such as char, this means setting them to 0.

Definition at line 622 of file basic_string.h.

void resize size_type  __n,
_CharT  __c
 

Resizes the string to the specified number of characters.

Parameters:
n Number of characters the string should contain.
c Character to fill any new elements.
This function will resize the string to the specified number of characters. If the number is smaller than the string's current size the string is truncated, otherwise the string is extended and new elements are set to c.

Definition at line 613 of file basic_string.tcc.

References basic_string::append(), basic_string::erase(), and basic_string::size().

Referenced by basic_string< char >::resize().

basic_string< _CharT, _Traits, _Alloc >::size_type rfind _CharT  __c,
size_type  __pos = npos
const
 

Find last position of a character.

Parameters:
c Character to locate.
pos Index of character to search back from (default 0).
Returns:
Index of last occurrence.
Starting from pos, searches backward for c within this string. If found, returns the index where it was found. If not found, returns npos.

Definition at line 768 of file basic_string.tcc.

References basic_string::npos, and basic_string::size().

size_type rfind const _CharT *  __s,
size_type  __pos = npos
const [inline]
 

Find last position of a C string.

Parameters:
s C string to locate.
pos Index of character to start search at (default 0).
Returns:
Index of start of last occurrence.
Starting from pos, searches backward for the value of s within this string. If found, returns the index where it begins. If not found, returns npos.

Definition at line 1625 of file basic_string.h.

basic_string< _CharT, _Traits, _Alloc >::size_type rfind const _CharT *  __s,
size_type  __pos,
size_type  __n
const
 

Find last position of a C substring.

Parameters:
s C string to locate.
pos Index of character to search back from.
n Number of characters from s to search for.
Returns:
Index of start of last occurrence.
Starting from pos, searches backward for the first n characters in s within this string. If found, returns the index where it begins. If not found, returns npos.

Definition at line 747 of file basic_string.tcc.

References std::min(), basic_string::npos, and basic_string::size().

size_type rfind const basic_string< _CharT, _Traits, _Alloc > &  __str,
size_type  __pos = npos
const [inline]
 

Find last position of a string.

Parameters:
str String to locate.
pos Index of character to search back from (default end).
Returns:
Index of start of last occurrence.
Starting from pos, searches backward for value of str within this string. If found, returns the index where it begins. If not found, returns npos.

Definition at line 1597 of file basic_string.h.

Referenced by basic_string< char >::find_last_of(), and basic_string< char >::rfind().

size_type size  )  const [inline]
 

null-termination.

Definition at line 584 of file basic_string.h.

Referenced by basic_string::append(), basic_string< char >::at(), bitset::bitset(), basic_string::compare(), basic_string< char >::compare(), money_get::do_get(), basic_string< char >::empty(), basic_string::find(), basic_string< char >::find(), basic_string::find_first_not_of(), basic_string< char >::find_first_not_of(), basic_string::find_first_of(), basic_string< char >::find_first_of(), basic_string::find_last_not_of(), basic_string< char >::find_last_not_of(), basic_string::find_last_of(), basic_string< char >::find_last_of(), basic_string< char >::insert(), std::operator+(), basic_string< char >::operator[](), basic_string< char >::push_back(), basic_string< char >::replace(), basic_string::reserve(), basic_string::resize(), basic_string::rfind(), basic_string< char >::rfind(), and basic_stringbuf::str().

basic_string substr size_type  __pos = 0,
size_type  __n = npos
const [inline]
 

Get a substring.

Parameters:
pos Index of first character (default 0).
n Number of characters in substring (default remainder).
Returns:
The new string.
Exceptions:
std::out_of_range If pos > size().
Construct and return a new string using the n characters starting at pos. If the string is too short, use the remainder of the characters. If pos is beyond the end of the string, out_of_range is thrown.

Definition at line 1897 of file basic_string.h.

void swap basic_string< _CharT, _Traits, _Alloc > &  __s  ) 
 

Swap contents with another string.

Parameters:
s String to swap with.
Exchanges the contents of this string with that of s in constant time.

Definition at line 500 of file basic_string.tcc.

References basic_string::_M_data(), basic_string::_M_ibegin(), basic_string::_M_iend(), basic_string::_M_rep(), and basic_string::get_allocator().

Referenced by basic_stringbuf::overflow().


Member Data Documentation

const basic_string< _CharT, _Traits, _Alloc >::size_type npos [static]
 

Value returned by various member functions when they fail.

Definition at line 72 of file basic_string.tcc.

Referenced by basic_string::find(), basic_string::find_first_not_of(), basic_string::find_first_of(), basic_string::find_last_not_of(), basic_string::find_last_of(), and basic_string::rfind().


The documentation for this class was generated from the following files:
Generated on Wed Apr 27 18:35:39 2005 for libstdc++ source by  doxygen 1.4.2