This chapter is a reference guide to the ANSI/ISO String class
that describes components for manipulating sequences of characters,
where characters may be of type char, wchar_t, or of a type defined in a C++ program.
The strings library is based on the ANSI/ISO string class description and includes
"21.3 Class Basic_string" defines facilities for character sequence manipulations.
This section defines a class template char_traits<charT> and two specializations for char and wchar_t types. These types are required by string and stream classes and
are passed to these classes as formal parameters charT and traits.
The topics in this section are:
Any object when treated sequentially can represent text. This term is not restricted to just char and wchar_t types
A class or type used to represent a character. This object must be POD (Plain Old Data).
A class that defines types and functions necessary for handling characteristics.
A null character termination string is a character sequence that proceeds the null character value charT(0).
These types are required by string and stream classes and are passed to these classes as formal parameters charT and traits.
Used for character type assignment.
Prototype:
static void assign
(char_type, const char_type); Used for bool equality checking.
Prototype:
static bool eg
(const char_type&, const char_type&); Used for bool less than checking.
Prototype:
static bool lt(const char_type&, const char_type&);
Prototype:
static int compare
(const char_type*, const char_type*, size_t n); Used when determining the length of a NTCTS.
Prototype:
static size_t length
(const char_type*); Used to find a character type in an array
Prototype:
static const char_type* find
(const char_type*, int n, const char_type&); Used to move one NTCTS to another even if the receiver contains the sting already.
Prototype:
static char_type* move
(char_type*, const char_type*, size_t); Used for copying a NTCTS that does not contain the NTCTS already.
Prototype:
static char_type* copy
(char_type*, const char_type*, size_t); Used for bool inequality checking.
Prototype:
static int_type not_eof
(const int_type&); Used to convert to a char type from an int_type
Prototype:
static char_type to_char_type
(const int_type&); Used to convert from a char type to an int_type.
Prototype:
static int_type to_int_type
(const char_type&); Prototype:
static bool eq_int_type
(const int_type&, const int_type& ); Used to store the state of the file buffer.
Prototype:
static state_type get_state
(pos_type pos); Used to test for the end of a file.
Prototype:
static int_type eof();
There are several types defined in the char_traits structure for both wide and conventional char types.
The template structure is overloaded for both the wchar_t type struct char_traits<wchar_t>. This specialization is used for string and stream usage.
NOTE The assign, eq and lt are the same as the =, == and < operators.
namespace std {
template<>
// struct char_traits<wchar_t> or
struct char_traits<char> {
typedef char char_type; typedef int int_type; typdef streamoff off_type; typedef streampos pos_type; typedef mbstate_t state_type; static void assign(char_type, const char_type); static bool eg(const char_type&, const char_tye&); static bool lt(const char_type&, const char_type&); static int compar(const char_type*, const char_type*, size_t n);
static size_t length(const char_type*); static const char_type* find(const char_type*, int n, const char_type&);
static char_type* move(char_type*, const char_type*, size_t);
static char_type* copy(char_type*, const char_type*, size_t);
static char_type* assign(char_type*, size_t, char_type); static int_type not_eof(const int_type&); static char_type to_char_type(const int_type&); static int_type to_int_type(const char_type&); static bool eq_int_type(const int_type&, const int_type& ); static state_type get_state(pos_type pos); static int_type eof(); };
}
The header <string> define string and trait classes used to manipulate character and wide character like template arguments.
Prototype:
namespace std {
template<class charT> struct char_traits;
template <> struct char_traits<char>;
template <> struct char_traits<wchar_t>;
template
<class charT,
class traits =char_traits<charT>,
class Allocator = allocator<charT> >
class basic_string;
template
<class charT, class traits, class Allocator>
basic_string <charT,traits, Allocator>
operator+
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT, traits, Allocator>& rhs); template
<class charT, class traits, class Allocator>
basic_string<charT,traits,Allocator>
operator+
const charT* lhs, const basic_string <charT, traits, Allocator>& rhs); template
<class charT, class traits, class Allocator>
basic_string<charT,traits,Allocator>
operator+
(charT lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
basic_string<charT,traits,Allocator>
operator+
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator>
basic_string<charT,traits,Allocator>
operator+
(const basic_string <charT,traits,Allocator>& lhs, charT rhs); template
<class charT, class traits, class Allocator>
bool operator==
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator==
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator==
(const basic_string<charT, traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator>
bool operator!=
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits, Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator!=
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator!=
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator>
bool operator<
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator<
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator>
bool operator<
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator>
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator>
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator>
bool operator>
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator<=
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator<=
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator>
bool operator<=
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator>=
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
bool operator>=
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator>
bool operator>=
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
void swap
(basic_string<charT,traits,Allocator>& lhs, basic_string<charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator>
basic_istream<charT,traits>&
operator>>
(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str); template
<class charT, class traits, class Allocator>
basic_ostream<charT, traits>&
operator<<
(basic_ostream<charT, traits>& os, const basic_string <charT,traits,Allocator>& str); template
<class charT, class traits, class Allocator>
basic_istream<charT,traits>&
getline
(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str, charT delim); template
<class charT, class traits, class Allocator>
basic_istream<charT,traits>&
getline
(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str); typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;
};
}
The class basic_string is used to store and manipulate a sequence of character like types
of varying length known as strings.
Memory for a string is allocated and deallocated as necessary by member functions.
The first element of the sequence is at position zero.
The iterators used by basic_string are random iterators and as such qualifies as a reversible container
The topics in this section include:
NOTE In general, the string size can be constrained by memory restrictions.
namespace std {
template
<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_string {
public: typedef traits traits_type;
typedef typename traits::char_type value_type;
typedef Allocator allocator_type;
typedef typename Allocator::size_type size_type;
typedef typename Allocator::difference_type
difference_type; typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference
const_reference; typedef typename Allocator::pointer pointer;
typedef typename Allocator::const_pointer
const_pointer; // typedef implementation defined iterator;
// typedef implementation definedconst_iterator;
typedef std::reverse_iterator<iterator>
reverse_iterator; typedef std::reverse_iterator<const_iterator>
const_reverse_iterator; static const size_type npos = -1;
explicit basic_string
(const Allocator& a = Allocator()); basic_string(const basic_string& str);
basic_string(const basic_string& str,
size_type pos, size_type n = npos, const Allocator& a = allocator_type()); basic_string
(const charT* s, size_type n, const Allocator& a = Allocator()); basic_string
(const charT* s, const Allocator& a = Allocator()); basic_string
(size_type n, charT c, const Allocator& a = Allocator()); template<class InputIterator>
basic_string
(InputIterator begin, InputIterator end, const Allocator& a = Allocator()); ~basic_string();
basic_string& operator= (const basic_string& str);
basic_string& operator=(const charT* s);
basic_string& operator=(charT c);
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
size_type size() const;
size_type length() const;
size_type max_size() const;
void resize(size_type n, charT c);
void resize(size_type n);
size_type capacity() const;
void reserve(size_type res_arg = 0);
void clear();
bool empty() const;
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
const_reference at(size_type n) const;
reference at(size_type n);
basic_string& operator+=(const basic_string& str);
basic_string& operator+=(const charT* s);
basic_string& operator+=(charT c);
basic_string& append(const basic_string& str);
basic_string& append(
const basic_string& str, size_type pos,size_type n); basic_string& append(const charT* s, size_type n);
basic_string& append(const charT* s);
basic_string& append(size_type n, charT c);
template<class InputIterator>
basic_string& append
(InputIterator first, InputIterator last); void push_back(const charT); Á
basic_string& assign(const basic_string&);
basic_string& assign
(const basic_string& str, size_type pos, size_type n); basic_string& assign(const charT* s, size_type n);
basic_string& assign(const charT* s);
basic_string& assign(size_type n, charT c);
template<class InputIterator>
basic_string& assign
(InputIterator first, InputIterator last); basic_string& insert
(size_type pos1, const basic_string& str); basic_string& insert
(size_type pos1, const basic_string& str, size_type pos2, size_type n); basic_string& insert
(size_type pos, const charT* s, size_type n); basic_string& insert
(size_type pos, const charT* s); basic_string& insert
(size_type pos, size_type n, charT c); iterator insert(iterator p, charT c = charT());
void insert(iterator p, size_type n, charT c);
template<class InputIterator>
void insert
(iterator p, InputIterator first, InputIterator last); basic_string& erase
(size_type pos = 0, size_type n = npos); iterator erase(iterator position);
iterator erase(iterator first, iterator last);
basic_string& replace
(size_type pos1, size_type n1, const basic_string& str); basic_string& replace
(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2); basic_string& replace
(size_type pos, size_type n1, const charT* s,size_type n2); basic_string& replace
(size_type pos, size_type n1, const charT* s); basic_string& replace
(size_type pos, size_type n1, size_type n2, charT c); basic_string& replace
(iterator i1, iterator i2, const basic_string& str); basic_string& replace
(iterator i1, iterator i2, const charT* s, size_type n); basic_string& replace(
iterator i1, iterator i2, const charT* s); basic_string& replace
(iterator i1, iterator i2, size_type n, charT c); template<class InputIterator>
basic_string& replace
(iterator i1, iterator i2, InputIterator j1, InputIterator j2); size_type copy
(charT* s, size_type n, size_type pos = 0) const; void swap(basic_string<charT,traits,Allocator>&);
const charT* c_str() const;
const charT* data() const;
allocator_type get_allocator() const;
size_type find
(const basic_string& str, size_type pos = 0) const; size_type find
(const charT* s, size_type pos, size_type n) const; size_type find
(const charT* s, size_type pos = 0) const; size_type find (charT c, size_type pos = 0) const;
size_type rfind
(const basic_string& str, size_type pos = npos) const; size_type rfind
(const charT* s, size_type pos, size_type n) const; size_type rfind
(const charT* s, size_type pos = npos) const; size_type rfind
(charT c, size_type pos = npos) const; size_type find_first_of
(const basic_string& str, size_type pos = 0) const; size_type find_first_of
(const charT* s, size_type pos, size_type n) const; size_type find_first_of
(const charT* s, size_type pos = 0) const; size_type find_first_of
(charT c, size_type pos = 0) const; size_type find_last_of
(const basic_string& str, size_type pos = npos) const; size_type find_last_of
(const charT* s, size_type pos, size_type n) const; size_type find_last_of
(const charT* s, size_type pos = npos) const; size_type find_last_of
(charT c, size_type pos = npos) const; size_type find_first_not_of
(const basic_string& str, size_type pos = 0) const; size_type find_first_not_of
(const charT* s, size_type pos, size_type n) const; size_type find_first_not_of
(const charT* s, size_type pos = 0) const; size_type find_first_not_of
(charT c, size_type pos = 0) const; size_type find_last_not_of
(const basic_string& str, size_type pos = npos) const; size_type find_last_not_of
(const charT* s, size_type pos, size_type n) const; size_type find_last_not_of
(const charT* s, size_type pos = npos) const; size_type find_last_not_of
(charT c, size_type pos = npos) const; basic_string substr
(size_type pos = 0, size_type n = npos) const; int compare(const basic_string& str) const;
int compare(
size_type pos1, size_type n1, const basic_string& str) const; int compare
(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2) const; int compare(const charT* s) const;
int compare(size_type pos1, size_type n1,
const charT* s) const; int compare(size_type pos1, size_type n1,
const charT* s, size_type n2) const; };
}
The class basic_string can have either of two implementations:
The interface and functionality are identical with both implementations. The only difference is performance. Which performs best is dependent upon usage patterns in each application.
The refcounted implementation ships as the default.
NOTE To enable the non-refcounted implementation un-comment #define _MSL_NO_REFCOUNT_STRING in <mslconfig>. The C++ library and precompiled headers must be rebuilt after making this change.
Constructor, destructor and assignment operators and functions.
The various basic_string constructors construct a string object
for character sequence manipulations. All constructors include
an -Allocator argument that is used for memory allocation.
Prototype:
explicit basic_string
(const Allocator& a = Allocator()); This default constructor, constructs an empty string. A zero sized string that may be copied to is created.
Prototype:
basic_string
(const basic_string& str, size_type pos = 0, size_type n = npos, const Allocator& a = Allocator()); This constructor takes a string class argument and creates a copy of that string, with size of the length of that string and a capacity at least as large as that string.
basic_string
(const charT* s, size_type n, const Allocator& a = Allocator()); This constructor takes a const char array argument and creates a copy of that array with the size limited
to the size_type argument.
The charT* argument shall not be a null pointer An exception is thrown upon failure Prototype:
basic_string
(const charT* s, const Allocator& a = Allocator()); This constructor takes an const char array argument. The size is determined by the size of the char array.
The charT* argument shall not be a null pointer Prototype:
basic_string
(size_type n, charT c, const Allocator& a = Allocator()); This constructor creates a string of size_type n size repeating charT c as the filler.
Alength_error is thrown if n is less than npos. Prototype:
template<class InputIterator>
basic_string
(InputIterator begin, InputIterator end, const Allocator& a = Allocator()); This iterator string takes InputIterator arguments and creates
a string with its first position starts with begin and its ending position is end. Size is the distance between beginning and end.
Deallocates the memory referenced by the basic_string object.
Prototype:
~basic_string ();
Assigns the input string, char array or char type to the current string.
Prototype:
basic_string& operator= (const basic_string& str);Remarks:
If *this and str are the same object has it has no effect.
Prototype:
basic_string& operator=(const charT* s);Remarks:
Used to assign a NCTCS to a string.
Prototype:
basic_string& operator=(charT c);Remarks:
Used to assign a single char type to a string.
Appends the string rhs to the current string.
Prototype:
string& operator+= (const string& rhs);
string& operator+= (const charT* s);
string& operator+= (charT s);
Both of the overloaded functions construct a string object from
the input s, and append it to the current string.
Return:
The assignment operator returns the this pointer.
Member functions for string iterator support.
Returns an iterator to the first character in the string
Prototype:
const_iterator begin() const;
Returns an iterator that is past the end value.
const_iterator end() const;
Returns an iterator that is equivalent to
Prototype:
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
Returns an iterator that is equivalent to
Prototype:
reverse_iterator(-begin()).
reverse_iterator rend();
const_reverse_iterator rend() const;
Member functions for determining a strings capacity.
Returns the size of the string.
Prototype:
Returns the length of the string
Prototype:
Returns the maximum size of the string.
Prototype:
Prototype:
void resize(size_type n, charT c);
If the size of the string is longer than size_type n, it shortens the string to n, if the size of the string is shorter than n it appends the string to size n with charT c or charT() if no filler is specified.
Returns the memory storage capacity.
Prototype:
A directive that indicates a planned change is memory size to allow for better memory management.
Prototype:
void reserve(size_type res_arg = 0);
Prototype:
void clear();
Prototype:
bool empty() const;Return:
Returns true if the size is equal to zero, otherwise false.
Member functions and operators for accessing individual string elements.
An operator used to access an indexed element of the string.
Prototype:
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
A function used to access an indexed element of the string.
Prototype:
const_reference at(size_type n) const;
reference at(size_type n);
Operators for appending a string.
An Operator used to append to the end of a string.
Prototype:
basic_string& operator+=(const basic_string& str);
basic_string& operator+=(const charT* s);
basic_string& operator+=(charT c);
Member functions for appending to the end of a string.
A function used to append to the end of a string.
Prototype:
basic_string& append(const basic_string& str);:
basic_string& append(
const basic_string& str, size_type pos,size_type n); basic_string& append(const charT* s, size_type n);:
basic_string& append(const charT* s);:
basic_string& append(size_type n, charT c);:
template<class InputIterator>
basic_string& append
(InputIterator first, InputIterator last); Assigns a string, Null Terminated Character Type Sequence or char type to the string.
Prototype:
basic_string& assign(const basic_string&);:
basic_string& assign
(const basic_string& str, size_type pos, size_type n); basic_string& assign(const charT* s, size_type n);:
basic_string& assign(const charT* s);:
basic_string& assign(size_type n, charT c);:
template<class InputIterator>
basic_string& assign
(InputIterator first, InputIterator last); If there is a size argument whichever is smaller the string size or argument value will be assigned.
Inserts a string, Null Terminated Character Type Sequence or char type into the string.
Prototype:
basic_string& insert
(size_type pos1, const basic_string& str); basic_string& insert
(size_type pos1, const basic_string& str, size_type pos2, size_type n); basic_string& insert
(size_type pos, const charT* s, size_type n); basic_string& insert
(size_type pos, const charT* s); basic_string& insert
(size_type pos, size_type n, charT c); iterator insert(iterator p, charT c = charT());:
void insert(iterator p, size_type n, charT c);:
template<class InputIterator>
void insert
(iterator p, InputIterator first, InputIterator last); Prototype:
basic_string& erase
(size_type pos = 0, size_type n = npos); iterator erase(iterator position);
iterator erase(iterator first, iterator last);Remarks:
Replaces the string with a string, Null Terminated Character Type Sequence or char type.
Prototype:
basic_string& replace
(size_type pos1, size_type n1, const basic_string& str); basic_string& replace
(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2); basic_string& replace
(size_type pos, size_type n1, const charT* s,size_type n2); basic_string& replace
(size_type pos, size_type n1, const charT* s); basic_string& replace
(size_type pos, size_type n1, size_type n2, charT c); basic_string& replace
(iterator i1, iterator i2, const basic_string& str); basic_string& replace
(iterator i1, iterator i2, const charT* s, size_type n); basic_string& replace(
iterator i1, iterator i2, const charT* s); basic_string& replace
(iterator i1, iterator i2, size_type n, charT c); template<class InputIterator>
basic_string& replace
(iterator i1, iterator i2, InputIterator j1, InputIterator j2); Copies a Null Terminated Character Type Sequence to a string up to the size designated.
Prototype:
size_type copy
(charT* s, size_type n, size_type pos = 0) const; The function copy does not pad the string with Null characters.
Prototype:
void swap(basic_string<charT,traits,Allocator>&);
Member functions for sequences of character operations.
Returns the string as a Null terminated character type sequence.
Prototype:
const charT* c_str() const;
Returns the string as an array without a Null terminator.
Prototype:
const charT* data() const;
Returns a copy of the allocator object used to create the string.
Prototype:
allocator_type get_allocator() const;
Finds a string, Null Terminated Character Type Sequence or char type in a string starting from the beginning.
Prototype:
size_type find
(const basic_string& str, size_type pos = 0) const; size_type find
(const charT* s, size_type pos, size_type n) const; size_type find
(const charT* s, size_type pos = 0) const; size_type find (charT c, size_type pos = 0) const;Return:
The found position or npos if not found.
Finds a string, Null Terminated Character Type Sequence or char type in a string testing backwards from the end.
Prototype:
size_type rfind
(const basic_string& str, size_type pos = npos) const; size_type rfind
(const charT* s, size_type pos, size_type n) const; size_type rfind
(const charT* s, size_type pos = npos) const; size_type rfind
(charT c, size_type pos = npos) const; The found position or npos if not found.
Finds the first position of one of the elements in the function's argument starting from the beginning.
Prototype:
size_type find_first_of
(const basic_string& str, size_type pos = 0) const; size_type find_first_of
(const charT* s, size_type pos, size_type n) const; size_type find_first_of
(const charT* s, size_type pos = 0) const; size_type find_first_of
(charT c, size_type pos = 0) const; The found position or npos if not found.
Finds the last position of one of the elements in the function's argument starting from the beginning.
Prototype:
size_type find_last_of
(const basic_string& str, size_type pos = npos) const; size_type find_last_of
(const charT* s, size_type pos, size_type n) const; size_type find_last_of
(const charT* s, size_type pos = npos) const; size_type find_last_of
(charT c, size_type pos = npos) const; The found position or npos if not found.
Finds the first position that is not one of the elements in the function's argument starting from the beginning.
Prototype:
size_type find_first_not_of
(const basic_string& str, size_type pos = 0) const; size_type find_first_not_of
(const charT* s, size_type pos, size_type n) const; size_type find_first_not_of
(const charT* s, size_type pos = 0) const; size_type find_first_not_of
(charT c, size_type pos = 0) const; The found position or npos if not found.
Finds the last position that is not one of the elements in the function's argument starting from the beginning.
Prototype:
size_type find_last_not_of
(const basic_string& str, size_type pos = npos) const; size_type find_last_not_of
(const charT* s, size_type pos, size_type n) const; size_type find_last_not_of
(const charT* s, size_type pos = npos) const; size_type find_last_not_of
(charT c, size_type pos = npos) const; The found position or npos if not found.
Returns a string if possible from beginning at the first arguments position to the last position.
Prototype:
basic_string substr
(size_type pos = 0, size_type n = npos) const; Compares a string, substring or Null Terminated Character Type Sequence with a lexicographical
comparison.
Prototype:
int compare(const basic_string& str) const;:
int compare(
size_type pos1, size_type n1, const basic_string& str) const; int compare
(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2) const; int compare(const charT* s) const;:
int compare
(size_type pos1, size_type n1, const charT* s, size_type n2 = npos) const; Less than zero if the string is smaller than the argument lexicographically, zero if the string is the same size as the argument lexicographically and greater than zero if the string is larger than the argument lexicographically.
Appends one string to another.
Prototype:
template
<class charT, class traits, class Allocator> basic_string<charT,traits,Allocator> operator+
(const basic_string <charT,traits, Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> basic_string<charT,traits,Allocator> operator+
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> basic_string<charT,traits,Allocator> operator+
(charT lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> basic_string<charT,traits,Allocator> operator+
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); template
<class charT, class traits, class Allocator> basic_string<charT,traits,Allocator> operator+
(const basic_string <charT,traits,Allocator>& lhs, charT rhs); Test for lexicographical equality.
Prototype:
template
<class charT, class traits, class Allocator> bool operator==
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator==
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator==
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); True if the strings match otherwise false.
Test for lexicographical inequality.
Prototype:
template
<class charT, class traits, class Allocator> bool operator!=
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator!=
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator!=
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); True if the strings do not match otherwise false.
Tests for a lexicographically less than condition.
Prototype:
template
<class charT, class traits, class Allocator> bool operator<
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator<
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator<
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); True if the first argument is lexicographically less than the second argument otherwise false.
Tests for a lexicographically greater than condition.
Prototype:
template
<class charT, class traits, class Allocator> bool operator>
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator>
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator>
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); True if the first argument is lexicographically greater than the second argument otherwise false.
Tests for a lexicographically less than or equal to condition.
Prototype:
template
<class charT, class traits, class Allocator> bool operator<=
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator<=
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator<=
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); True if the first argument is lexicographically less than or equal to the second argument otherwise false.
Tests for a lexicographically greater than or equal to condition.
Prototype:
template
<class charT, class traits, class Allocator> bool operator>=
(const basic_string <charT,traits,Allocator>& lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator>=
(const charT* lhs, const basic_string <charT,traits,Allocator>& rhs); template
<class charT, class traits, class Allocator> bool operator>=
(const basic_string <charT,traits,Allocator>& lhs, const charT* rhs); True if the first argument is lexicographically greater than or equal to the second argument otherwise false.
This non member swap exchanges the first and second arguments.
Prototype:
template
<class charT, class traits, class Allocator> void swap
(basic_string<charT,traits,Allocator>& lhs, basic_string <charT,traits,Allocator>& rhs); Overloaded inserters and extractors for basic_string types.
Overloaded extractor for stream input operations.
Prototype:
template
<class charT, class traits, class Allocator> basic_istream<charT,traits>& operator>>
(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str); Characters are extracted and appended until n characters are stored or end-of-file occurs on the input sequence;
Inserts characters from a string object from into a output stream.
Prototype:
template
<class charT, class traits, class Allocator> basic_ostream<charT, traits>& operator<<
(basic_ostream<charT, traits>& os, const basic_string <charT,traits,Allocator>& str); Extracts characters from a stream and appends them to a string.
Prototype:
template
<class charT, class traits, class Allocator> basic_istream<charT,traits>& getline
(basic_istream<charT,traits>& is, basic_string <charT,traits,Allocator>& str, charT delim); template
<class charT, class traits, class Allocator> basic_istream<charT,traits>& getline
(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str) Extracts characters from a stream and appends them to the string until the end-of-file occurs on the input sequence (in which case, the getline function calls setstate(eofbit) or the delimiter is encountered in which case, the delimiter is
extracted but not appended.
If the function extracts no characters, it calls setstate(failbit) in which case it may throw an exception.
The standard requires C++ versions of the standard libraries for use with characters and Null Terminated Character Type Sequences.
The standard provides for namespace and character type support.
Headers <cctype.h> and <cwtype.h>:
| <cctype.h> |
<cwctype.h> |
<cctype.h> |
<cwctype.h> |
|---|---|---|---|
| Macros |
The standard provides for namespace and wide character type for Null Terminated Character Type Sequence functionality.
Headers <cstring.h> and <wchar.h>:
| <cstring.h> |
<wchar.h> |
<cstring.h> |
<wchar.h> |
|---|---|---|---|
| Type |
|||
| Macro |
|||
The standard provides for namespace and wide character support for manipulation and conversions of input and output and character and character sequences.
Additional <wchar.h> and <stdlib.h> support:
| wchar.h |
wchar.h |
wchar.h |
<cstdlib.h> |
|---|---|---|---|