Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

basic_string

Library:  Strings


Does not inherit

Local Index

Members

Non-Members

Summary

A templatized class for handling sequences of character-like entities. string and wstring are specialized variations of basic_string for chars and wchar_ts, respectively.typedef basic_string <char> string;typedef basic_string <wchar_t> wstring;

Synopsis

#include <string>

namespace std {
  template <class charT,
            class traits = char_traits<charT>,
            class Allocator = allocator<charT> >
  class basic_string;
}

Description

Class basic_string is a homogeneous collection of character-like entities that includes string functions such as compare(), append(), assign(), insert(), remove(), and replace(), along with various searches. The class also functions as an STL sequence container that provides random access iterators. This allows some of the generic algorithms to apply to strings.

Any underlying character-like type may be used as long as an appropriate char_traits class is included or the default traits class is applicable.

Interface

Constructors

In all cases, the Allocator parameter is used for storage management.

explicit 
basic_string (const Allocator& a = Allocator());

data()

a non-null pointer that is copyable and can have 0 added to it

size()

0

capacity()

an unspecified value

basic_string (const basic_string<T, traits, 
               Allocator>& str);
basic_string (const basic_string& str, size_type pos,
              size_type n= npos, const allocator&
              a=allocator());
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 start, InputIterator finish,
              const Allocator& a = Allocator());

Destructor

~basic_string ();

Operators

basic_string&
operator=(const basic_string& str);
basic_string& 
operator=(const charT * s);
basic_string& 
operator=(charT c);
const_reference 
operator[](size_type pos) const;
reference 
operator[](size_type pos);
basic_string& 
operator+=(const basic_string& s);
basic_string& 
operator+=(const charT* s);
basic_string& 
operator+=(charT c);

Iterators

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;

Allocator

allocator_type get_allocator() const;

Member Functions

basic_string& 
append(const basic_string& s, size_type pos, 
        size_type npos);
basic_string&
append(const basic_string& s);
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 start, InputIterator finish);
void 
push_back(charT c);
basic_string&
assign(const basic_string& s);
basic_string& 
assign(const basic_string& s,
       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 start, InputIterator finish);
const_reference 
at(size_type pos) const;
reference 
at(size_type pos);
size_type 
capacity() const;
void
clear();
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 char_type* s) const;
int
compare(size_type pos, size_type n1, 
        const char_type* s) const;
int
compare(size_type pos, size_type n1, const char_type* s, 
        size_type n2) const;
size_type 
copy(charT* s, size_type n, size_type pos = 0) const;
const charT* 
c_str() const;
const charT* 
data() const;
bool empty() const;
basic_string& 
erase(size_type pos = 0, size_type n = npos);
iterator 
erase(iterator p);
iterator 
erase(iterator start, iterator finish);
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
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_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_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;
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;
basic_string&
insert(size_type pos1, const basic_string& s);
basic_string& 
insert(size_type pos, const basic_string& s,
       size_type pos2 = 0, size_type n = npos);
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);
void 
insert(iterator p, size_type n, charT c);
template<class InputIterator>
void
insert(iterator p, InputIterator start, InputIterator finish);
size_type 
length() const;
size_type 
max_size() 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;
basic_string&
replace(size_type pos, size_type n1, const basic_string& s);
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);
void 
reserve(size_type res_arg=0);
void
resize(size_type n, charT c);
void
resize(size_type n);
size type
size()const;
basic_string 
substr(size_type pos = 0, size_type n = npos) const;
void 
swap(basic_string& s);

Nonmember Operators

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 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 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>
void swap(basic_string<charT,traits,Allocator>& a, 
           basic_string<charT,traits,Allocator>& b); 
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);

Nonmember Functions

template <class Stream, class charT, class traits, class Allocator>
basic_istream<charT, traits>&
getline(basic_istream<charT, traits>& is, 
         basic_string<charT, traits allocator> &str, charT delim);

Example

See Also

allocator, string, wstring

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 21.3



Previous fileTop of DocumentContentsIndex pageNext file