Professional Documents
Culture Documents
TXT
Visual C++
Table of Contents
. <iso646.h> . <wchar.h>
extractions
<iterator> -- (STL) for defining several templates that help define
and manipulate iterators
<limits> -- for testing numeric type properties
<list> -- (STL) for defining a template class that implements a
list container
<locale> -- for defining several classes and templates that control
locale-specific behavior, as in the iostreams classes
<map> -- (STL) for defining template classes that implement
associative containers
<memory> -- (STL) for defining several templates that allocate and
free storage for various container classes
<numeric> -- (STL) for defining several templates that implement
useful numeric functions
<ostream> -- for defining the template class that performs
insertions
<queue> -- (STL) for defining a template class that implements a
queue container
<set> -- (STL) for defining template classes that implement
associative containers with unique elements
<sstream> -- for defining several iostreams template classes that
manipulate string containers
<stack> -- (STL) for defining a template class that implements a
stack container
<stdexcept> -- for defining several classes useful for reporting
exceptions
<streambuf> -- for defining template classes that buffer iostreams
operations
<string> -- for defining a template class that implements a string
container
<strstream> -- for defining several iostreams classes that
manipulate in-memory character sequences
<utility> -- (STL) for defining several templates of general
utility
<valarray> -- for defining several classes and template classes
that support value-oriented arrays
<vector> -- (STL) for defining a template class that implements a
vector container
The Standard C++ library also includes the 18 headers from the
Standard C library, sometimes with small alterations. Most of the
functions in the header files below are documented in the Run-Time
Library Reference, so they are not discussed in this Standard C++
Library reference.
which promotes all library names into the current namespace. If you
include one of the C standard headers, such as <stdio.h>, the
individual names declared or defined in that header are promoted
for you. Note that macro names are not subject to the rules for
nesting namespaces.
The Standard C++ library obeys much the same conventions as the
Standard C library, plus a few more outlined here.
Except for macro names, which obey no scoping rules, all names in
the Standard C++ library are declared in the std namespace.
Including a Standard C++ header does not introduce any library
names into the current namespace. You must, for example, refer to
the standard input stream cin as std::cin, even after including the
header <iostream> that declares it. Alternatively, you can
incorporate all members of the std namespace into the current
namespace by writing:
On the other hand, there are some restrictions you can count on:
Iostreams Conventions
The simplest use of iostreams requires only that you include the
header <iostream>. You can then extract values from cin, to read
the standard input. The rules for doing so are outlined in the
description of the class basic_istream. You can also insert values
to cout, to write the standard output. The rules for doing so are
outlined in the description of the class basic_ostream. Format
control common to both extractors and insertors is managed by the
You can perform the same iostreams operations on files that you
open by name, using the classes declared in <fstream>. To convert
between iostreams and objects of class basic_string, use the
classes declared in <sstream>. And to do the same with C strings,
use the classes declared in <strstream>.
Before the target environment calls the function main, and after it
stores any constant initial values you specify in all objects that
have static duration, the program executes any remaining
constructors for such static objects. The order of execution is not
specified between translation units, but you can nevertheless
assume that four iostreams objects are properly initialized for use
by these static constructors. These control several text streams:
During program termination, you can also use these objects within
the destructors called for static objects.
STL Conventions
Iterator Conventions
The right arrow means "can be replaced by." So any algorithm that
calls for an output iterator should work well with a forward
iterator, for example, but not the other way around.
Finally, for read/write access to a sequence, you can use any of:
Algorithm Conventions
lThe phrase "in the range [A, B)" means the sequence of zero or
more discrete values beginning with A up to but not including
B. A range is valid only if B is reachable from A: You can
store A in an object N (N = A), increment the object zero or
more times (++N), and have the object compare equal to B after
a finite number of increments (N == B).
lThe phrase "each N in the range [A, B)" means that N begins
with the value A and is incremented zero or more times until it
equals the value B. The case N == B is not in the range.
lThe phrase "the lowest value of N in the range [A, B) such that
X" means that the condition X is determined for each N in the
range [A, B) until the condition X is met.
lThe phrase "the highest value of N in the range [A, B) such
that X" usually means that X is determined for each N in the
range [A, B). The function stores in K a copy of N each time
the condition X is met. If any such store occurs, the function
replaces the final value of N (which equals B) with the value
of K. For a bidirectional or random-access iterator, however,
it can also mean that N begins with the highest value in the
range and is decremented over the range until the condition X
is met.
lExpressions such as X - Y, where X and Y can be iterators other
than random-access iterators, are intended in the mathematical
sense. The function does not necessarily evaluate operator- if
it must determine such a value. The same is true for
expressions such as X + N and X - N, where N is an integer
type.
You manipulate all these kinds of files in much the same way -- by
calling library functions. You include the standard header
<stdio.h> to declare most of these functions.
Before you can perform many of the operations on a file, the file
must be opened. Opening a file associates it with a stream, a data
structure within the Standard C library that glosses over many
differences among files of various kinds. The library maintains the
state of each stream in an object of type FILE.
lWhether you intend to read data from the file or write data to
it, or both.
lWhether you intend to generate new contents for the file (or
Once the file is successfully opened, you can determine whether the
stream is byte-oriented (a byte stream) or wide-oriented (a wide
stream). Wide-oriented streams are supported only with Amendment 1.
A stream is initially unbound. Calling certain functions to operate
on the stream makes it byte oriented, while certain other functions
make it wide oriented. Once established, a stream maintains its
orientation until it is closed by a call to fclose or freopen.
lEmpty files
lSpace characters at the end of a
lPartial lines (by omitting the NL at the end of a file)
lCharacters other than the printable characters, NL, and
(horizontal tab)
If you follow these rules, the sequence of characters you read from
a text stream (either as byte or multibyte characters) will match
the sequence of characters you wrote to the text stream when you
created the file. Otherwise, the library functions can remove a
file you create if the file is empty when you close it. Or they can
alter or delete characters you write to the file.
for positioning relative to the end of the stream. You can obtain
and alter the current file-position indicator the same as for a
text stream. Moreover, the offsets used by ftell and fseek count
bytes from the beginning of the stream (which is byte zero), so
integer arithmetic on these offsets yields predictable results.
Controlling Streams
You can close a file by calling fclose, after which the address of
the FILE object is invalid.
Stream States
For the stream s, the call fwide(s, 0) is always valid and never
causes a change of state. Any other call to fwide, or to any of the
five groups of functions described above, causes the state
transition shown in the state diagram. If no such transition is
shown, the function call is invalid.
The state diagram also shows that you must call one of the position
functions between most write and read operations:
Containers
namespace std {
template<class T, class A>
class Cont;
// TEMPLATE FUNCTIONS
template<class T, class A>
bool operator==(
const Cont<T, A>& lhs,
const Cont<T, A>& rhs);
template<class T, class A>
bool operator!=(
const Cont<T, A>& lhs,
const Cont<T, A>& rhs);
template<class T, class A>
bool operator<(
const Cont<T, A>& lhs,
const Cont<T, A>& rhs);
template<class T, class A>
bool operator>(
const Cont<T, A>& lhs,
const Cont<T, A>& rhs);
template<class T, class A>
bool operator<=(
const Cont<T, A>& lhs,
const Cont<T, A>& rhs);
template<class T, class A>
bool operator>=(
const Cont<T, A>& lhs,
const Cont<T, A>& rhs);
template<class T, class A>
void swap(
const Cont<T, A>& lhs,
const Cont<T, A>& rhs);
};
deque
list
map
multimap
multiset
set
vector
Cont
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
Cont::allocator_type
typedef A allocator_type;
Cont::begin
Cont::clear
Cont::const_iterator
typedef T6 const_iterator;
Cont::const_reference
typedef T3 const_reference;
Cont::const_reverse_iterator
typedef T8 const_reverse_iterator;
Cont::difference_type
typedef T1 difference_type;
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
Cont::empty
Cont::end
The member function returns an iterator that points just beyond the
end of the sequence.
Cont::erase
Cont::get_allocator
A get_allocator() const;
Cont::iterator
typedef T5 iterator;
The type describes an object that can serve as an iterator for the
controlled sequence. It is described here as a synonym for the
unspecified type T5.
Cont::max_size
The member function returns the length of the longest sequence that
the object can control.
Cont::rbegin
Cont::reference
typedef T2 reference;
Cont::rend
Cont::reverse_iterator
typedef T7 reverse_iterator;
Cont::size
Cont::size_type
typedef T0 size_type;
Cont::swap
Cont::value_type
typedef T4 value_type;
operator!=
operator==
operator<
operator<=
operator>
operator>=
bool operator>=(
const Cont <T, A>& lhs,
const Cont <T, A>& rhs);
swap
<algorithm>
namespace std {
template<class InIt, class Fun>
Fun for_each(InIt first, InIt last, Fun f);
template<class InIt, class T>
InIt find(InIt first, InIt last, const T& val);
template<class InIt, class Pred>
InIt find_if(InIt first, InIt last, Pred pr);
template<class FwdIt1, class FwdIt2>
FwdIt1 find_end(FwdIt1 first1, FwdIt1 last1,
FwdIt2 first2, FwdIt2 last2);
template<class FwdIt1, class FwdIt2, class Pred>
FwdIt1 find_end(FwdIt1 first1, FwdIt1 last1,
FwdIt2 first2, FwdIt2 last2, Pred pr);
template<class FwdIt1, class FwdIt2>
FwdIt1 find_first_of(FwdIt1 first1, FwdIt1 last1,
FwdIt2 first2, FwdIt2 last2);
template<class FwdIt1, class FwdIt2, class Pred>
FwdIt1 find_first_of(FwdIt1 first1, FwdIt1 last1,
FwdIt2 first2, FwdIt2 last2, Pred pr);
template<class FwdIt>
FwdIt adjacent_find(FwdIt first, FwdIt last);
template<class FwdIt, class Pred>
FwdIt adjacent_find(FwdIt first, FwdIt last, Pred pr);
size_t count(InIt first, InIt last,
adjacent_find
template<class FwdIt>
FwdIt adjacent_find(FwdIt first, FwdIt last);
template<class FwdIt, class Pred>
FwdIt adjacent_find(FwdIt first, FwdIt last, Pred pr);
The second template function behaves the same, except that the
predicate is pr(*(first + N), *(first + N + 1)).
binary_search
copy
copy_backward
count
count_if
equal
The first template function returns true only if, for each N in the
range [0, last1 - first1), the predicate *(first1 + N) == *(first2
The second template function behaves the same, except that the
predicate is pr(*(first1 + N), *(first2 + N)).
equal_range
fill
fill_n
find
find_end
The second template function behaves the same, except that the
predicate is pr(*(first1 + N + M), *(first2 + N + M)).
find_first_of
The second template function behaves the same, except that the
predicate is pr(*(first1 + N), *(first2 + M)).
find_if
for_each
generate
generate_n
includes
inplace_merge
template<class BidIt>
void inplace_merge(BidIt first, BidIt middle, BidIt last);
template<class BidIt, class Pred>
void inplace_merge(BidIt first, BidIt middle, BidIt last, Pred p
iter_swap
lexicographical_compare
lower_bound
make_heap
template<class RanIt>
void make_heap(RanIt first, RanIt last);
template<class RanIt, class Pred>
void make_heap(RanIt first, RanIt last, Pred pr);
max
template<class T>
const T& max(const T& x, const T& y);
template<class T, class Pred>
Microsoft-Specific:
To avoid conflicts with min and max in WINDEF.H, use _MIN and _MAX
instead. These macros evaluate to _cpp_min and _cpp_max,
respectively.
END Microsoft-Specific
max_element
template<class FwdIt>
FwdIt max_element(FwdIt first, FwdIt last);
template<class FwdIt, class Pred>
FwdIt max_element(FwdIt first, FwdIt last, Pred pr);
merge
sequence.
min
template<class T>
const T& min(const T& x, const T& y);
template<class T, class Pred>
const T& min(const T& x, const T& y, Pred pr);
Microsoft-Specific:
To avoid conflicts with min and max in WINDEF.H, use _MIN and _MAX
instead. These macros evaluate to _cpp_min and _cpp_max,
respectively.
END Microsoft-Specific
min_element
template<class FwdIt>
FwdIt min_element(FwdIt first, FwdIt last);
template<class FwdIt, class Pred>
FwdIt min_element(FwdIt first, FwdIt last, Pred pr);
mismatch
The second template function behaves the same, except that the
predicate is pr(*(first1 + N), *(first2 + N)).
next_permutation
template<class BidIt>
bool next_permutation(BidIt first, BidIt last);
template<class BidIt, class Pred>
bool next_permutation(BidIt first, BidIt last, Pred pr);
nth_element
template<class RanIt>
void nth_element(RanIt first, RanIt nth, RanIt last);
template<class RanIt, class Pred>
void nth_element(RanIt first, RanIt nth, RanIt last, Pred pr);
partial_sort
template<class RanIt>
void partial_sort(RanIt first, RanIt middle, RanIt last);
template<class RanIt, class Pred>
void partial_sort(RanIt first, RanIt middle, RanIt last, Pred pr
partial_sort_copy
partition
The predicate must not alter its operand. The function evaluates pr
(*(first + N)) exactly last - first times, and swaps (last -
first) / 2 pairs of elements, at most.
pop_heap
template<class RanIt>
void pop_heap(RanIt first, RanIt last);
template<class RanIt, class Pred>
void pop_heap(RanIt first, RanIt last, Pred pr);
prev_permutation
template<class BidIt>
bool prev_permutation(BidIt first, BidIt last);
template<class BidIt, class Pred>
bool prev_permutation(BidIt first, BidIt last, Pred pr);
to form the next permutation. The function returns true only if the
resulting sequence is not the initial permutation. Otherwise, the
resultant sequence is the one next smaller lexicographically than
the original sequence. No two elements may have equivalent
ordering.
push_heap
template<class RanIt>
void push_heap(RanIt first, RanIt last);
template<class RanIt, class Pred>
void push_heap(RanIt first, RanIt last, Pred pr);
random_shuffle
template<class RanIt>
void random_shuffle(RanIt first, RanIt last);
template<class RanIt, class Fun>
void random_shuffle(RanIt first, RanIt last, Fun& f);
remove
if (!(*(first + N) == val))
*X++ = *(first + N);
once for each N in the range [0, last - first). It then returns X.
Thus, the function removes from the sequence all elements for which
the predicate *(first + N) == val is true, without altering the
relative order of remaining elements, and returns the iterator
value that designates the end of the revised sequence.
remove_copy
if (!(*(first + N) == val))
*x++ = *(first + N);
once for each N in the range [0, last - first). It then returns x.
Thus, the function removes from the sequence all elements for which
the predicate *(first + N) == val is true, without altering the
relative order of remaining elements, and returns the iterator
value that designates the end of the revised sequence.
remove_copy_if
if (!pr(*(first + N)))
*x++ = *(first + N);
once for each N in the range [0, last - first). It then returns x.
Thus, the function removes from the sequence all elements for which
the predicate pr(*(first + N)) is true, without altering the
relative order of remaining elements, and returns the iterator
value that designates the end of the revised sequence.
remove_if
if (!pr(*(first + N)))
*X++ = *(first + N);
once for each N in the range [0, last - first). It then returns X.
Thus, the function removes from the sequence all elements for which
the predicate pr(*(first + N)) is true, without altering the
relative order of remaining elements, and returns the iterator
value that designates the end of the revised sequence.
replace
if (*(first + N) == vold)
*(first + N) = vnew;
replace_copy
if (*(first + N) == vold)
*(x + N) = vnew;
else
*(x + N) = *(first + N)
replace_copy_if
if (pr(*(first + N)))
*(x + N) = val;
else
*(x + N) = *(first + N)
replace_if
if (pr(*(first + N)))
*(first + N) = val;
reverse
template<class BidIt>
void reverse(BidIt first, BidIt last);
reverse_copy
rotate
template<class FwdIt>
void rotate(FwdIt first, FwdIt middle, FwdIt last);
rotate_copy
search
The second template function behaves the same, except that the
predicate is pr(*(first1 + N + M), *(first2 + M)).
search_n
The second template function behaves the same, except that the
predicate is pr(*(first + N + M), val).
set_difference
set_intersection
set_symmetric_difference
set_union
sort
template<class RanIt>
void sort(RanIt first, RanIt last);
template<class RanIt, class Pred>
void sort(RanIt first, RanIt last, Pred pr);
sort_heap
template<class RanIt>
void sort_heap(RanIt first, RanIt last);
template<class RanIt, class Pred>
void sort_heap(RanIt first, RanIt last, Pred pr);
stable_partition
The predicate must not alter its operand. The function evaluates pr
(*(first + N)) exactly last - first times, and swaps at most ceil
((last - first) * log(last - first)) pairs of elements. (Given
enough temporary storage, it can replace the swaps with 2 * (last -
first) assignments, at most.)
stable_sort
template<class RanIt>
void stable_sort(RanIt first, RanIt last);
template<class RanIt, class Pred>
void stable_sort(RanIt first, RanIt last, Pred pr);
swap
template<class T>
void swap(T& x, T& y);
swap_ranges
transform
unique
template<class FwdIt>
FwdIt unique(FwdIt first, FwdIt last);
template<class FwdIt, class Pred>
FwdIt unique(FwdIt first, FwdIt last, Pred pr);
if (N == 0 || !(*(first + N) == V))
V = *(first + N), *X++ = V;
once for each N in the range [0, last - first). It then returns X.
Thus, the function repeatedly removes from the sequence the second
of a pair of elements for which the predicate *(first + N) == *
(first + N - 1) is true, until only the first of a sequence of
equal elements survives. It does so without altering the relative
order of remaining elements, and returns the iterator value that
designates the end of the revised sequence. The function evaluates
the predicate last - first times, at most.
unique_copy
if (N == 0 || !(*(first + N) == V))
V = *(first + N), *x++ = V;
once for each N in the range [0, last - first). It then returns x.
Thus, the function repeatedly removes from the sequence it copies
the second of a pair of elements for which the predicate *(first +
N) == *(first + N - 1) is true, until only the first of a sequence
of equal elements survives. It does so without altering the
relative order of remaining elements, and returns the iterator
value that designates the end of the copied sequence.
upper_bound
<bitset>
namespace std {
template<size_t N>
class bitset;
// TEMPLATE FUNCTIONS
template<class E, class T, size_t N>
basic_istream<E, T>& operator>>(basic_istream<E, T>& is,
bitset<N>& x);
template<class E, class T, size_t N>
basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os,
const bitset<N>& x);
};
bitset
template<size_t N>
class bitset {
public:
typedef bool element_type;
class reference;
bitset();
bitset(unsigned long val);
template<class E, class T, class A>
explicit bitset(const string<E, T, A>& str,
string<E, T, A>size_type pos = 0,
string<E, T, A>size_type n = string<E, T, A>::npos);
bitset<N>& operator&=(const bitset<N>& rhs);
bitset::any
The member function returns true if any bit is set in the bit
sequence.
bitset::at
bitset::bitset
bitset();
bitset(unsigned long val);
explicit bitset(const string& str,
size_t pos = 0, size_t n = -1);
The first constructor resets all bits in the bit sequence. The
second constructor sets only those bits at position j for which val
& 1 << j is nonzero.
is replaced by:
bitset::bitset_size
bitset::count
The member function returns the number of bits set in the bit
sequence.
bitset::element_type
bitset::flip
bitset<N>& flip();
bitset<N>& flip(size_t pos);
The first member function flips all bits in the bit sequence, then
bitset::none
The member function returns true if none of the bits are set in the
bit sequence.
bitset::operator!=
The member operator function returns true only if the bit sequence
stored in *this differs from the one stored in rhs.
bitset::operator&=
bitset::operator<<
bitset::operator<<=
bitset::operator==
The member operator function returns true only if the bit sequence
stored in *this is the same as the one stored in rhs.
bitset::operator>>
bitset::operator>>=
bitset::operator[]
bitset::operator^=
bitset::operator|=
bitset::operator~
bitset<N> operator~();
bitset::reference
class reference {
public:
reference& operator=(bool b};
reference& operator=(const reference& x);
bool operator~() const;
operator bool() const;
reference& flip();
};
bitset::reset
bitset<N>& reset();
bitset<N>& reset(size_t pos);
The first member function resets all bits in the bit sequence, then
returns *this. The second member function throws out_of_range if
size() <= pos. Otherwise, it resets the bit at position pos, then
returns *this.
bitset::set
bitset<N>& set();
bitset<N>& set(size_t pos, bool val = true);
The first member function resets all bits in the bit sequence, then
returns *this. The second member function throws out_of_range if
size() <= pos. Otherwise, it stores val in the bit at position pos,
then returns *this.
bitset::size
bitset::test
bitset::to_string
is replaced by:
bitset::to_ulong
operator<<
operator>>
<cassert>
abs
template<class T>
T abs(const complex<T>& x);
arg
template<class T>
T arg(const complex<T>& x);
complex
template<class T>
class complex {
public:
typedef T value_type;
T real() const;
T imag() const;
complex(const T& re = 0, const T& im = 0);
complex(const complex& x);
complex& operator=(const complex& rhs);
complex& operator+=(const complex& rhs);
complex& operator-=(const complex& rhs);
complex& operator*=(const complex& rhs);
complex& operator/=(const complex& rhs);
complex& operator=(const T& rhs);
complex& operator=(const T& rhs);
complex& operator+=(const T& rhs);
complex& operator-=(const T& rhs);
complex& operator*=(const T& rhs);
complex& operator/=(const T& rhs);
friend complex<T>
operator+(const complex<T>& lhs, const T& rhs);
friend complex<T>
operator+(const T& lhs, const complex<T>& rhs);
friend complex<T>
operator-(const complex<T>& lhs, const T& rhs);
friend complex<T>
operator-(const T& lhs, const complex<T>& rhs);
friend complex<T>
operator*(const complex<T>& lhs, const T& rhs);
friend complex<T>
operator*(const T& lhs, const complex<T>& rhs);
friend complex<T>
operator/(const complex<T>& lhs, const T& rhs);
friend complex<T>
operator/(const T& lhs, const complex<T>& rhs);
friend bool operator==(const complex<T>& lhs, const T& rhs);
friend bool operator==(const T& lhs, const complex<T>& rhs);
friend bool operator!=(const complex<T>& lhs, const T& rhs);
friend bool operator!=(const T& lhs, const complex<T>& rhs);
};
complex::complex
template<class U>
complex(const complex<U>& x);
is replaced by:
complex::imag
T imag() const;
complex::operator*=
The first member function replaces the stored real and imaginary
parts with those corresponding to the complex product of *this and
rhs. It then returns *this.
The second member function multiplies both the stored real part and
the stored imaginary part with rhs. It then returns *this.
template<class U>
complex& operator*=(const complex<U>& rhs);
is replaced by:
complex::operator+=
The first member function replaces the stored real and imaginary
parts with those corresponding to the complex sum of *this and rhs.
It then returns *this.
The second member function adds rhs to the stored real part. It
then returns *this.
template<class U>
complex& operator+=(const complex<U>& rhs);
is replaced by:
complex::operator-=
The first member function replaces the stored real and imaginary
parts with those corresponding to the complex difference of *this
and rhs. It then returns *this.
The second member function subtracts rhs from the stored real part.
It then returns *this.
template<class U>
complex& operator-=(const complex<U>& rhs);
is replaced by:
complex::operator/=
The first member function replaces the stored real and imaginary
parts with those corresponding to the complex quotient of *this and
rhs. It then returns *this.
The second member function multiplies both the stored real part and
template<class U>
complex& operator/=(const complex<U>& rhs);
is replaced by:
complex::operator=
The first member function replaces the stored real part with
rhs.real() and the stored imaginary part with rhs.imag(). It then
returns *this.
The second member function replaces the stored real part with rhs
and the stored imaginary part with zero. It then returns *this.
template<class U>
complex& operator=(const complex<U>& rhs);
is replaced by:
complex::real
T real() const;
complex::value_type
typedef T value_type;
complex<double>
class complex<double> {
public:
complex(double re = 0, double im = 0);
complex(const complex<float>& x);
explicit complex(const complex<long double>& x);
// rest same as template class complex
};
complex<float>
class complex<float> {
public:
complex(float re = 0, float im = 0);
explicit complex(const complex<double>& x);
explicit complex(const complex<long double>& x);
// rest same as template class complex
};
complex<long double>
conjg
template<class T>
complex<T> conjg(const complex<T>& x);
cos
template<class T>
complex<T> cos(const complex<T>& x);
cosh
template<class T>
complex<T> cosh(const complex<T>& x);
exp
template<class T>
complex<T> exp(const complex<T>& x);
imag
template<class T>
T imag(const complex<T>& x);
log
template<class T>
complex<T> log(const complex<T>& x);
The function returns the logarithm of x. The branch cuts are along
the negative real axis.
log10
template<class T>
complex<T> log10(const complex<T>& x);
norm
template<class T>
T norm(const complex<T>& x);
operator!=
template<class T>
bool operator!=(const complex<T>& lhs, const complex<T>& rhs);
template<class T>
bool operator!=(const complex<T>& lhs, const T& rhs);
template<class T>
operator*
template<class T>
complex<T> operator*(const complex<T>& lhs, const complex<T>& rh
template<class T>
complex<T> operator*(const complex<T>& lhs, const T& rhs);
template<class T>
complex<T> operator*(const T& lhs, const complex<T>& rhs);
The operators each convert both operands to the return type, then
return the complex product of the converted lhs and rhs.
operator+
template<class T>
complex<T> operator+(const complex<T>& lhs, const complex<T>& rh
template<class T>
complex<T> operator+(const complex<T>& lhs, const T& rhs);
template<class T>
complex<T> operator+(const T& lhs, const complex<T>& rhs);
template<class T>
complex<T> operator+(const complex<T>& lhs);
The binary operators each convert both operands to the return type,
then return the complex sum of the converted lhs and rhs.
operator-
template<class T>
complex<T> operator-(const complex<T>& lhs, const complex<T>& rh
template<class T>
complex<T> operator-(const complex<T>& lhs, const T& rhs);
template<class T>
complex<T> operator-(const T& lhs, const complex<T>& rhs);
template<class T>
complex<T> operator-(const complex<T>& lhs);
The binary operators each convert both operands to the return type,
then return the complex difference of the converted lhs and rhs.
operator/
template<class T>
complex<T> operator/(const complex<T>& lhs, const complex<T>& rh
template<class T>
complex<T> operator/(const complex<T>& lhs, const T& rhs);
template<class T>
The operators each convert both operands to the return type, then
return the complex quotient of the converted lhs and rhs.
operator<<
The template function inserts the complex value x into the output
stream os, effectively by executing:
operator==
template<class T>
bool operator==(const complex<T>& lhs, const complex<T>& rhs);
template<class T>
bool operator==(const complex<T>& lhs, const T& rhs);
template<class T>
bool operator==(const T& lhs, const complex<T>& rhs);
operator>>
polar
template<class T>
complex<T> polar(const T& rho, const T& theta = 0);
The function returns the complex value whose magnitude is rho and
whose phase angle is theta.
pow
template<class T>
complex<T> pow(const complex<T>& x, int y);
template<class T>
complex<T> pow(const complex<T>& x, const T& y);
template<class T>
complex<T> pow(const complex<T>& x, const complex<T>& y);
template<class T>
complex<T> pow(const T& x, const complex<T>& y);
real
template<class T>
T real(const complex<T>& x);
sin
template<class T>
complex<T> sin(const complex<T>& x);
sinh
template<class T>
complex<T> sinh(const complex<T>& x);
sqrt
template<class T>
complex<T> sqrt(const complex<T>& x);
The function returns the square root of x, with phase angle in the
half-open interval (-pi/2, pi/2]. The branch cuts are along the
negative real axis.
__STD_COMPLEX
#define __STD_COMPLEX
<csetjmp>
namespace std {
#include <setjmp.h>
};
deque
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. Note that allocator is not copied when
the object is assigned.
deque::allocator_type
typedef A allocator_type;
deque::assign
template<class InIt>
void assign(InIt first, InIt last);
template<class Size, class T2>
void assign(Size n, const T2& x = T2());
deque::at
deque::back
reference back();
const_reference back() const;
deque::begin
deque::clear
deque::const_iterator
typedef T1 const_iterator;
deque::const_reference
deque::const_reverse_iterator
deque::deque
All constructors store the allocator object al (or, for the copy
constructor, x.get_allocator()) in allocator and initialize the
controlled sequence. The first constructor specifies an empty
initial controlled sequence. The second constructor specifies a
repetition of n elements of value x. The third constructor
specifies a copy of the sequence controlled by x. The last
constructor specifies the sequence [first, last).
template<class InIt>
deque(InIt first, InIt last, const A& al = A());
is replaced by:
deque::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
deque::empty
deque::end
deque::erase
deque::front
reference front();
const_reference front() const;
deque::get_allocator
A get_allocator() const;
deque::insert
template<class InIt>
void insert(iterator it, InIt first, InIt last);
is replaced by:
deque::iterator
typedef T0 iterator;
deque::max_size
The member function returns the length of the longest sequence that
the object can control.
deque::operator[]
deque::pop_back
void pop_back();
deque::pop_front
void pop_front();
deque::push_back
deque::push_front
deque::rbegin
deque::reference
deque::rend
deque::resize
deque::reverse_iterator
deque::size
deque::size_type
deque::swap
deque::value_type
operator!=
operator==
operator<
operator<=
operator>
operator>=
swap
<exception>
namespace std {
class exception;
class bad_exception;
typedef void (*terminate_handler)();
typedef void (*unexpected_handler)();
terminate_handler set_terminate(terminate_handler ph) throw();
unexpected_handler set_unexpected(unexpected_handler ph) throw()
void terminate();
void unexpected();
bool uncaught_exception();
};
bad_exception
exception
class exception {
public:
exception() throw();
exception(const exception& rhs) throw();
exception& operator=(const exception& rhs) throw();
virtual ~exception() throw();
virtual const char *what() const throw();
};
The class serves as the base class for all exceptions thrown by
certain expressions and by the Standard C++ library. The C string
value returned by what() is left unspecified by the default
constructor, but may be defined by the constructors for certain
derived classes. None of the member functions throw any exceptions.
set_terminate
set_unexpected
terminate_handler
unexpected_handler
terminate
void terminate();
uncaught_exception
bool uncaught_exception();
unexpected
void unexpected();
<fstream>
namespace std {
template<class E, class T = char_traits<E> >
class basic_filebuf;
typedef basic_filebuf<char> filebuf;
typedef basic_filebuf<wchar_t> wfilebuf;
template<class E, class T = char_traits<E> >
class basic_ifstream;
typedef basic_ifstream<char> ifstream;
typedef basic_ifstream<wchar_t> wifstream;
template<class E, class T = char_traits<E> >
class basic_ofstream;
typedef basic_ofstream<char> ofstream;
typedef basic_ofstream<wchar_t> wofstream;
template<class E, class T = char_traits<E> >
class basic_fstream;
typedef basic_fstream<char> fstream;
typedef basic_fstream<wchar_t> wfstream;
};
basic_filebuf
basic_filebuf::basic_filebuf
basic_filebuf();
basic_filebuf::close
basic_filebuf *close();
basic_filebuf::is_open
bool is_open();
The member function returns true if the file pointer is not a null
pointer.
basic_filebuf::open
The member function endeavors to open the file with file name s, by
calling fopen(s, strmode). Here strmode is determined from mode & ~
(ate & | binary):
basic_filebuf::overflow
basic_filebuf::pbackfail
basic_filebuf::seekoff
For a file opened for both reading and writing, both the input and
output streams are positioned in tandem. To switch between
inserting and extracting, you must call either pubseekoff or
pubseekpos. Calls to pubseekoff (and hence to seekoff) have various
limitations for text streams, binary streams, and wide streams.
basic_filebuf::seekpos
For a file opened for both reading and writing, both the input and
output streams are positioned in tandem. To switch between
inserting and extracting, you must call either pubseekoff or
pubseekpos. Calls to pubseekoff (and hence to seekoff) have various
limitations for text streams, binary streams, and wide streams.
basic_filebuf::setbuf
basic_filebuf::sync
int sync();
basic_filebuf::underflow
basic_fstream
basic_fstream::basic_fstream
explicit basic_fstream();
explicit basic_fstream(const char *s,
ios_base::openmode mode = ios_base::in | ios_base::out);
basic_fstream::close
voidclose();
basic_fstream::is_open
bool is_open();
basic_fstream::open
basic_fstream::rdbuf
basic_ifstream
basic_ifstream::basic_ifstream
explicit basic_ifstream();
explicit basic_ifstream(const char *s,
ios_base::openmode mode = ios_base::in);
basic_ifstream::close
void close();
basic_ifstream::is_open
bool is_open();
basic_ifstream::open
basic_ifstream::rdbuf
basic_ofstream
basic_ofstream::basic_ofstream
explicit basic_ofstream();
explicit basic_ofstream(const char *s,
ios_base::openmode which = ios_base::out | ios_base::trunc);
setstate(failbit).
basic_ofstream::close
void close();
basic_ofstream::is_open
bool is_open();
basic_ofstream::open
basic_ofstream::rdbuf
filebuf
fstream
ifstream
ofstream
wfilebuf
wfstream
wifstream
wofstream
<functional>
namespace std {
// TEMPLATE CLASSES
template<class Arg, class Result>
struct unary_function;
template<class Arg1, class Arg2, class Result>
struct binary_function;
template<class T>
struct plus;
template<class T>
struct minus;
template<class T>
struct multiplies;
template<class T>
struct divides;
template<class T>
struct modulus;
template<class T>
struct negate;
template<class T>
struct equal_to;
template<class T>
struct not_equal_to;
template<class T>
struct greater;
template<class T>
struct less;
template<class T>
struct greater_equal;
template<class T>
struct less_equal;
template<class T>
struct logical_and;
template<class T>
struct logical_or;
template<class T>
struct logical_not;
template<class Pred>
struct unary_negate;
template<class Pred>
struct binary_negate;
template<class Pred>
class binder1st;
template<class Pred>
class binder2nd;
template<class Arg, class Result>
class pointer_to_unary_function;
template<class Arg1, class Arg2, class Result>
class pointer_to_binary_function;
template<class R, class T>
struct mem_fun_t;
template<class R, class T, class A>
struct mem_fun1_t;
template<class R, class T>
struct mem_fun_ref_t;
template<class R, class T, class A>
struct mem_fun1_ref_t;
// TEMPLATE FUNCTIONS
template<class Pred>
unary_negate<Pred> not1(const Pred& pr);
template<class Pred>
binary_negate<Pred> not2(const Pred& pr);
template<class Pred, class T>
binder1st<Pred> bind1st(const Pred& pr, const T& x);
template<class Pred, class T>
binder2nd<Pred> bind2nd(const Pred& pr, const T& x);
template<class Arg, class Result>
pointer_to_unary_function<Arg, Result>
ptr_fun(Result (*)(Arg));
template<class Arg1, class Arg2, class Result>
pointer_to_binary_function<Arg1, Arg2, Result>
ptr_fun(Result (*)(Arg1, Arg2));
binary_function
Hence, all such binary functions can refer to their first argument
type as first_argument_type, their second argument type as
second_argument_type, and their return type as result_type.
binary_negate
template<class Pred>
class binary_negate
: public binary_function<Pred::first_argument_type,
Pred::second_argument_type, bool> {
public:
explicit binary_negate(const Pred& pr);
bool operator()(const first_argument_type& x,
const second_argument_type& y) const;
};
bind1st
bind2nd
binder1st
template<class Pred>
class binder1st
: public unary_function<Pred::second_argument_type,
Pred::result_type> {
public:
binder1st(const Pred& pr, const Pred::first_argument_type x);
result_type operator()(const argument_type& y) const;
protected:
Pred op;
Pred::first_argument_type value;
};
binder2nd
template<class Pred>
class binder2nd
: public unary_function<Pred::first_argument_type,
Pred::result_type> {
public:
binder2nd(const Pred& pr, const Pred::second_argument_type y);
result_type operator()(const argument_type& x) const;
protected:
Pred op;
Pred::second_argument_type value;
};
divides
template<class T>
struct divides : public binary_function<T, T, T> {
T operator()(const T& x, const T& y) const;
};
equal_to
template<class T>
struct equal_to : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
greater
template<class T>
struct greater : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
greater_equal
template<class T>
struct greater_equal : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
less
template<class T>
struct less : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
less_equal
template<class T>
struct less_equal : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
logical_and
template<class T>
struct logical_and : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
logical_not
template<class T>
struct logical_not : public unary_function<T, bool> {
bool operator()(const T& x) const;
};
logical_or
template<class T>
struct logical_or : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
mem_fun
mem_fun_ref
mem_fun_ref_t
mem_fun_t
R operator()(T *p);
};
mem_fun1
mem_fun1_ref
mem_fun1_ref_t
mem_fun1_t
minus
template<class T>
struct minus : public binary_function<T, T, T> {
T operator()(const T& x, const T& y) const;
};
modulus
template<class T>
struct modulus : public binary_function<T, T, T> {
T operator()(const T& x, const T& y) const;
};
multiplies
template<class T>
struct multiplies : public binary_function<T, T, T> {
T operator()(const T& x, const T& y) const;
};
negate
template<class T>
struct negate : public unary_function<T, T> {
T operator()(const T& x) const;
};
not1
template<class Pred>
unary_negate<Pred> not1(const Pred& pr);
not2
template<class Pred>
binary_negate<Pred> not2(const Pred& pr);
not_equal_to
template<class T>
struct not_equal_to : public binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const;
};
plus
template<class T>
struct plus : public binary_function<T, T, T> {
pointer_to_binary_function
pointer_to_unary_function
ptr_fun
unary_function
result_type operator()(argument_type)
Hence, all such unary functions can refer to their sole argument
type as argument_type and their return type as result_type.
unary_negate
template<class Pred>
class unary_negate
: public unary_function<Pred::argument_type, bool> {
public:
explicit unary_negate(const Pred& pr);
bool operator()(const argument_type& x) const;
};
<iomanip>
namespace std {
// MANIPULATORS
T1 resetiosflags(ios_base::fmtflags mask);
T2 setiosflags(ios_base::fmtflags mask);
T3 setbase(int base);
template<class E>
T4 setfill(E c);
T5 setprecision(int n);
T6 setw(int n);
};
resetiosflags
T1 resetiosflags(ios_base::fmtflags mask);
setiosflags
T2 setiosflags(ios_base::fmtflags mask);
setbase
T3 setbase(int base);
setfill
template<class E>
T4 setfill(E fillch);
setprecision
T5 setprecision(int prec);
setw
T6 setw(int wide);
<ios>
basic_ios . fpos .
ios . ios_base . streamoff . streampos .
streamsize . wios . wstreampos
namespace std {
typedef T1 streamoff;
typedef T2 streamsize;
class ios_base;
// TEMPLATE CLASSES
template <class E, class T = char_traits<E> >
class basic_ios;
typedef basic_ios<char, char_traits<char> > ios;
typedef basic_ios<wchar_t, char_traits<wchar_t> > wios;
template <class St>
class fpos;
typedef fpos<mbstate_t> streampos;
typedef fpos<mbstate_t> wstreampos;
// MANIPULATORS
ios_base& boolalpha(ios_base& str);
ios_base& noboolalpha(ios_base& str);
ios_base& showbase(ios_base& str);
ios_base& noshowbase(ios_base& str);
ios_base& showpoint(ios_base& str);
ios_base& noshowpoint(ios_base& str);
ios_base& showpos(ios_base& str);
ios_base& noshowpos(ios_base& str);
ios_base& skipws(ios_base& str);
ios_base& noskipws(ios_base& str);
ios_base& unitbuf(ios_base& str);
ios_base& nounitbuf(ios_base& str);
ios_base& uppercase(ios_base& str);
ios_base& nouppercase(ios_base& str);
ios_base& internal(ios_base& str);
ios_base& left(ios_base& str);
ios_base& right(ios_base& str);
ios_base& dec(ios_base& str);
ios_base& hex(ios_base& str);
ios_base& oct(ios_base& str);
ios_base& fixed(ios_base& str);
ios_base& scientific(ios_base& str);
};
calls noskipws(istr).
basic_ios
basic_ios::bad
basic_ios::basic_ios
basic_ios::char_type
typedef E char_type;
basic_ios::clear
basic_ios::copyfmt
basic_ios::eof
basic_ios::exceptions
The first member function returns the stored exception mask. The
second member function stores except in the exception mask and
returns its previous stored value. Note that storing a new
exception mask can throw an exception just like the call clear
( rdstate()).
basic_ios::fail
basic_ios::fill
E fill() const;
E fill(E ch);
The first member function returns the stored fill character. The
second member function stores ch in the fill character and returns
its previous stored value.
basic_ios::good
basic_ios::imbue
basic_ios::init
lrdbuf() returns sb
ltie() returns a null pointer
lrdstate() returns goodbit if sb is nonzero; otherwise, it
returns badbit
lexceptions() returns goodbit
lflags() returns skipws | dec
lwidth() returns zero
lprecision() returns 6
lfill() returns the space character
lgetloc() returns locale::classic()
liword returns zero and pword returns a null pointer for all
argument values
basic_ios::int_type
basic_ios::narrow
basic_ios::off_type
basic_ios::operator void *
basic_ios::operator!
basic_ios::pos_type
basic_ios::rdbuf
basic_ios::rdstate
basic_ios::setstate
basic_ios::tie
The first member function returns the stored tie pointer. The
second member function stores str in the tie pointer and returns
its previous stored value.
basic_ios::widen
E narrow(char ch);
boolalpha
dec
fixed
fpos
The template class describes an object that can store all the
fpos::fpos
The first constructor stores a zero offset and the objects state
and fposn. The second constructor stores the offset off, relative
to the beginning of file and in the initial conversion state (if
that matters). If off is -1, the resulting object represents an
invalid stream position.
fpos::get_fpos_t
fpos::operator!=
fpos::operator+
fpos::operator+=
The member function adds off to the stored offset member object,
then returns *this. For positioning within a file, the result is
generally valid only for binary streams that do not have a state-
dependent encoding.
fpos::operator-
fpos::operator-=
fpos::operator==
fpos::operator streamoff
The member function returns the stored offset member object, plus
any additional offset stored as part of the fpos_t member object.
fpos::state
St state() const;
void state(St state);
The first member function returns the value stored in the St member
object. The second member function stores state in the St member
object.
hex
internal
ios
ios_base
class ios_base {
public:
class failure;
typedef T1 fmtflags;
static const fmtflags boolalpha, dec, fixed, hex, internal,
left, oct, right, scientific, showbase, showpoint,
showpos, skipws, unitbuf, uppercase, adjustfield,
basefield, floatfield;
typedef T2 iostate;
static const iostate badbit, eofbit, failbit, goodbit;
typedef T3 openmode;
static const openmode app, ate, binary, in, out, trunc;
typedef T4 seekdir;
static const seekdir beg, cur, end;
typedef T5 event;
static const event copyfmt_event, erase_event,
copyfmt_event;
class Init;
ios_base& operator=(const ios_base& rhs);
fmtflags flags() const;
fmtflags flags(fmtflags fmtfl);
fmtflags setf(fmtflags fmtfl);
fmtflags setf(fmtflags fmtfl, fmtflags mask);
void unsetf(fmtflags mask);
streamsize precision() const;
streamsize precision(streamsize prec);
streamsize width() const;
stramsize width(streamsize wide);
locale imbue(const locale& loc);
locale getloc() const;
static int xalloc();
long& iword(int idx);
void *& pword(int idx);
typedef void *(event_callback(event ev, ios_base& ios, int idx);
void register_callback(event_callback pfn, int idx);
static bool sync_with_stdio(bool sync = true);
protected:
ios_base();
};
The class describes the storage and member functions common to both
input and output streams that do not depend on the template
parameters. (The template class basic_ios describes what is common
and is dependent on template parameters.)
ios_base::event
typedef T5 event;
static const event copyfmt_event, erase_event,
imbue_event;
ios_base::event_callback
ios_base::failure
The member class serves as the base class for all exceptions thrown
by the member function clear in template class basic_ios. The value
returned by what() is what_arg.data().
ios_base::flags
The first member function returns the stored format flags. The
second member function stores fmtfl in the format flags and returns
its previous stored value.
ios_base::fmtflags
typedef T1 fmtflags;
static const fmtflags boolalpha, dec, fixed, hex, internal,
left, ,
oct right, scientific, showbase, showpoint,
ios_base::getloc
ios_base::imbue
The member function stores loc in the locale object, then reports
the callback event imbue_event. It returns the previous stored
value.
ios_base::Init
class Init {
};
ios_base::ios_base
ios_base();
ios_base::iostate
typedef T2 iostate;
static const iostate badbit, eofbit, failbit, goodbit;
ios_base::iword
ios_base::openmode
typedef T3 openmode;
static const openmode app, ate, binary, in, out, trunc;
ios_base::operator=
ios_base::precision
The first member function returns the stored display precision. The
second member function stores prec in the display precision and
returns its previous stored value.
ios_base::pword
ios_base::register_callback
The member function pushes the pair {pfn, idx} onto the stored
callback stack. When a callback event ev is reported, the functions
are called, in reverse order of registry, by the expression (*pfn)
(ev, *this, idx).
ios_base::seekdir
typedef T4 seekdir;
static const seekdir beg, cur, end;
ios_base::setf
ios_base::sync_with_stdio
ios_base::unsetf
ios_base::width
The first member function returns the stored field width. The
second member function stores wide in the field width and returns
its previous stored value.
ios_base::xalloc
left
noboolalpha
noshowbase
noshowpoint
noshowpos
noskipws
nounitbuf
nouppercase
oct
right
scientific
showbase
showpoint
showpos
skipws
streamoff
typedef T1 streamoff;
streampos
streamsize
typedef T2 streamsize;
unitbuf
uppercase
wios
wstreampos
<iosfwd>
namespace std {
// TYPE DEFINITIONS
typedef T1 streamoff;
typedef T2 streampos;
// TEMPLATES
template<class E>
class char_traits;
class char_traits<char>;
class char_traits<wchar_t>;
template<class E, class T = char_traits<E> >
class basic_ios;
template<class E, class T = char_traits<E> >
class istreambuf_iterator;
template<class E, class T = char_traits<E> >
class ostreambuf_iterator;
template<class E, class T = char_traits<E> >
class basic_streambuf;
template<class E, class T = char_traits<E> >
class basic_istream;
template<class E, class T = char_traits<E> >
class basic_ostream;
template<class E, class T = char_traits<E> >
class basic_iostream;
template<class E, class T = char_traits<E> >
class basic_stringbuf;
template<class E, class T = char_traits<E> >
class basic_istringstream;
template<class E, class T = char_traits<E> >
class basic_ostringstream;
template<class E, class T = char_traits<E> >
class basic_stringstream;
template<class E, class T = char_traits<E> >
class basic_filebuf;
template<class E, class T = char_traits<E> >
class basic_ifstream;
template<class E, class T = char_traits<E> >
class basic_ofstream;
template<class E, class T = char_traits<E> >
class basic_fstream;
// char TYPE DEFINITIONS
typedef basic_ios<char, char_traits<char> > ios;
typedef basic_streambuf<char, char_traits<char> > streambuf;
typedef basic_istream<char, char_traits<char> > istream;
typedef basic_ostream<char, char_traits<char> > ostream;
typedef basic_iostream<char, char_traits<char> > iostream;
typedef basic_stringbuf<char, char_traits<char> > stringbuf;
typedef basic_istringstream<char, char_traits<char> > istringstream;
typedef basic_ostringstream<char, char_traits<char> > ostringstream;
typedef basic_stringstream<char, char_traits<char> > stringstream;
typedef basic_filebuf<char, char_traits<char> > filebuf;
typedef basic_ifstream<char, char_traits<char> > ifstream;
typedef basic_ofstream<char, char_traits<char> > ofstream;
typedef basic_fstream<char, char_traits<char> > fstream;
// wchar_t TYPE DEFINITIONS
typedef basic_ios<wchar_t, char_traits<wchar_t> > wios;
typedef basic_streambuf<wchar_t, char_traits<wchar_t> > wstreambuf;
typedef basic_istream<wchar_t, char_traits<wchar_t> > wistream;
typedef basic_ostream<wchar_t, char_traits<wchar_t> > wostream;
typedef basic_iostream<wchar_t, char_traits<wchar_t> > wiostream;
typedef basic_stringbuf<wchar_t, char_traits<wchar_t> > wstringbuf;
typedef basic_istringstream<wchar_t, char_traits<wchar_t> > wistring
typedef basic_ostringstream<wchar_t, char_traits<wchar_t> > wostring
typedef basic_stringstream<wchar_t, char_traits<wchar_t> > wstringst
typedef basic_filebuf<wchar_t, char_traits<wchar_t> > wfilebuf;
typedef basic_ifstream<wchar_t, char_traits<wchar_t> > wifstream;
typedef basic_ofstream<wchar_t, char_traits<wchar_t> > wofstream;
typedef basic_fstream<wchar_t, char_traits<wchar_t> > wfstream;
};
<iostream>
namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
};
#include <iostream>
void marker()
{ // called by some constructor
ios_base::Init unused_name;
cout << "called fun" << endl;
}
cerr
cin
clog
cout
wcerr
wcin
wclog
wcout
<istream>
namespace std {
// DECLARATIONS
template<class E, class T = char_traits<E> >
class basic_istream;
typedef basic_istream<char, char_traits<char> > istream;
typedef basic_istream<wchar_t, char_traits<wchar_t> > wistream;
template<class E, class T = char_traits<E> >
class basic_iostream;
typedef basic_iostream<char, char_traits<char> > iostream;
typedef basic_iostream<wchar_t, char_traits<wchar_t> > wiostream
// EXTRACTORS
template<class E, class T>
basic_istream<E, T>& operator>>(basic_istream<E, T> is, E *s
template<class E, class T>
basic_istream<E, T>& operator>>(basic_istream<E, T> is, E& c
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is
// MANIPULATOR
template class<E, T>
basic_istream<E, T>& ws(basic_istream<E, T> is);
};
basic_iostream
public:
explicit basic_iostream(basic_streambuf<E, T> *sb);
virtual ~basic_iostream();
};
basic_istream
basic_istream& unget();
pos_type tellg();
basic_istream& seekg(pos_type pos);
basic_istream& seekg(off_type off, ios_base::seek_dir way);
int sync();
};
basic_istream::basic_istream
basic_istream::gcount
basic_istream::get
int_type get();
basic_istream& get(E& c);
basic_istream& get(E *s, streamsize n);
basic_istream& get(E *s, streamsize n, E delim);
basic_istream& get(basic_streambuf<E, T> *sb);
basic_istream& get(basic_streambuf<E, T> *sb, E delim);
The second function extracts the int_type element x the same way.
If x compares equal to T::eof(x), the function calls setstate
(failbit). Otherwise, it stores T::to_char_type(x) in c. The
function returns *this.
The sixth function extracts elements and inserts them into sb.
Extraction stops on end-of-file or on an element that compares
equal to delim (which is not extracted). It also stops, without
extracting the element in question, if an insertion fails or throws
an exception (which is caught but not rethrown). If the function
extracts no elements, it calls setstate(failbit). In any case, the
function returns *this.
basic_istream::getline
basic_istream::ignore
basic_istream& ignore(streamsize n = 1,
int_type delim = T::eof());
basic_istream::ipfx
If, after any such preparation, good() is false, the function calls
setstate(failbit). In any case, the function returns good().
basic_istream::isfx
void isfx();
basic_istream::operator>>
basic_istream& operator>>(
basic_istream& (*pf)(basic_istream&));
basic_istream& operator>>(
basic_ios<E, T>& (*pf)(basic_ios<E, T>&));
basic_istream& operator>>(
ios_base<E, T>& (*pf)(ios_base<E, T>&));
basic_istream& operator>>(
basic_streambuf<E, T> *sb);
basic_istream& operator>>(bool& n);
basic_istream& operator>>(short& n);
basic_istream& operator>>(unsigned short& n);
basic_istream& operator>>(int& n);
basic_istream& operator>>(unsigned int& n);
basic_istream& operator>>(long& n);
basic_istream& operator>>(unsigned long& n);
basic_istream& operator>>(void *& n);
basic_istream& operator>>(float& n);
basic_istream& operator>>(double& n);
basic_istream& operator>>(long double& n);
The function:
basic_istream& operator>>(
basic_streambuf<E, T> *sb);
The function:
The functions:
*this.
The functions:
basic_istream::peek
int_type peek();
basic_istream::putback
basic_istream::read
basic_istream::readsome
basic_istream::seekg
basic_istream::sentry
class sentry {
public:
explicit sentry(basic_istream<E, T>& is, bool noskip = false);
operator bool() const;
};
basic_istream::sync
int sync();
basic_istream::tellg
pos_type tellg();
basic_istream::unget
basic_istream& unget();
iostream
istream
operator>>
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is, si
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is, si
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is, un
template<class T>
basic_istream<char, T>& operator>>(basic_istream<char, T> is, un
wiostream
wistream
ws
<iterator>
namespace std {
struct input_iterator_tag;
struct output_iterator_tag;
struct forward_iterator_tag;
struct bidirectional_iterator_tag;
struct random_access_iterator_tag;
// TEMPLATE CLASSES
template<class C, class T, class Dist>
struct iterator;
template<class It>
struct iterator_traits;
template<class T>
struct iterator_traits<T *>
template<class BidIt, class T, class Ref,
class Ptr, class Dist>
class reverse_bidirectional_iterator;
template<class RanIt, class T, class Ref,
class Ptr, class Dist>
class reverse_iterator;
template<class Cont>
class back_insert_iterator;
template<class Cont>
class front_insert_iterator;
template<class Cont>
class insert_iterator;
template<class T, class Dist>
class istream_iterator;
template<class T>
class ostream_iterator;
template<class E, class T>
class istreambuf_iterator;
template<class E, class T>
class ostreambuf_iterator;
// TEMPLATE FUNCTIONS
template<class BidIt, class T, class Ref, class Ptr, class Dist>
bool operator==(
const reverse_bidirectional_iterator<BidIt, T, Ref,
Ptr, Dist>& lhs,
const reverse_bidirectional_iterator<BidIt, T, Ref,
Ptr, Dist>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
bool operator==(
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& lhs,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class T, class Dist>
bool operator==(
const istream_iterator<T, Dist>& lhs,
const istream_iterator<T, Dist>& rhs);
template<class E, class T>
bool operator==(
const istreambuf_iterator<E, T>& lhs,
const istreambuf_iterator<E, T>& rhs);
template<class BidIt, class T, class Ref, class Ptr, class Dist>
bool operator!=(
const reverse_bidirectional_iterator<BidIt, T, Ref,
Ptr, Dist>& lhs,
const reverse_bidirectional_iterator<BidIt, T, Ref,
Ptr, Dist>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
bool operator!=(
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& lhs,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class T, class Dist>
bool operator!=(
const istream_iterator<T, Dist>& lhs,
const istream_iterator<T, Dist>& rhs);
template<class E, class T>
bool operator!=(
const istreambuf_iterator<E, T>& lhs,
const istreambuf_iterator<E, T>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
bool operator<(
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>&mmp lhs,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
bool operator>(
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>&mmp lhs,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
bool operator<=(
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>&mmp lhs,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
bool operator>=(
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>&mmp lhs,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
Dist operator-(
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& lhs,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class RanIt, class T, class Ref, class Ptr, class Dist>
reverse_iterator<RanIt, T, Ref, Ptr, Dist> operator+(
Dist n,
const reverse_iterator<RanIt, T, Ref, Ptr, Dist>& rhs);
template<class Cont>
back_insert_iterator<Cont> back_inserter(Cont& x);
template<class Cont>
front_insert_iterator<Cont> front_inserter(Cont& x);
template<class Cont, class Iter>
insert_iterator<Cont> inserter(Cont& x, Iter it);
template<class InIt, class Dist>
void advance(InIt& it, Dist n);
template<class Init, class Dist>
ptrdiff_t distance(InIt first, InIt last);
};
advance
back_insert_iterator
template<class Cont>
class back_insert_iterator
: public iterator<output_iterator_tag, void, void> {
public:
typedef Cont container_type;
typedef Cont::value_type value_type;
explicit back_insert_iterator(Cont& x);
back_insert_iterator& operator=(const Cont::value_type& val);
back_insert_iterator& operator*();
back_insert_iterator& operator++();
back_insert_iterator operator++(int);
protected:
Cont& container;
};
back_insert_iterator::back_insert_iterator
back_insert_iterator::container_type
back_insert_iterator::operator*
back_insert_iterator& operator*();
back_insert_iterator::operator++
back_insert_iterator& operator++();
back_insert_iterator operator++(int);
back_insert_iterator::operator=
back_insert_iterator::value_type
back_inserter
template<class Cont>
back_insert_iterator<Cont> back_inserter(Cont& x);
bidirectional_iterator_tag
struct bidirectional_iterator_tag
: public forward_iterator_tag {
};
distance
forward_iterator_tag
struct forward_iterator_tag
: public input_iterator_tag {
};
front_insert_iterator
template<class Cont>
class front_insert_iterator
: public iterator<output_iterator_tag, void, void> {
public:
typedef Cont container_type;
typedef Cont::value_type value_type;
explicit front_insert_iterator(Cont& x);
front_insert_iterator& operator=(const Cont::value_type& val);
front_insert_iterator& operator*();
front_insert_iterator& operator++();
front_insert_iterator operator++(int);
protected:
Cont& container;
};
front_insert_iterator::container_type
front_insert_iterator::front_insert_iterator
front_insert_iterator::operator*
front_insert_iterator& operator*();
front_insert_iterator::operator++
front_insert_iterator& operator++();
front_insert_iterator operator++(int);
front_insert_iterator::operator=
front_insert_iterator::value_type
front_inserter
template<class Cont>
front_insert_iterator<Cont> front_inserter(Cont& x);
input_iterator_tag
struct input_iterator_tag {
};
insert_iterator
template<class Cont>
class insert_iterator
: public iterator<output_iterator_tag, void, void> {
public:
typedef Cont container_type;
typedef Cont::value_type value_type;
explicit insert_iterator(Cont& x, Cont::iterator it);
insert_iterator& operator=(const Cont::value_type& val);
insert_iterator& operator*();
insert_iterator& operator++();
insert_iterator& operator++(int);
protected:
Cont& container;
Cont::iterator iter;
};
insert_iterator::container_type
insert_iterator::insert_iterator
insert_iterator::operator*
insert_iterator& operator*();
insert_iterator::operator++
insert_iterator& operator++();
insert_iterator& operator++(int);
insert_iterator::operator=
insert_iterator::value_type
inserter
istream_iterator
istream_iterator(istream_type& is);
const U& operator*() const;
const U *operator->() const;
istream_iterator<U, E, T>& operator++();
istream_iterator<U, E, T> operator++(int);
};
istream_iterator::char_type
typedef E char_type;
istream_iterator::istream_iterator
istream_iterator();
istream_iterator(istream_type& is);
istream_iterator::istream_type
istream_iterator::operator*
istream_iterator::operator->
istream_iterator::operator++
istream_iterator::traits_type
typedef T traits_type;
istreambuf_iterator
istreambuf_iterator::char_type
typedef E char_type;
istreambuf_iterator::equal
istreambuf_iterator::int_type
istreambuf_iterator::istream_type
istreambuf_iterator::istreambuf_iterator
istreambuf_iterator::operator*
istreambuf_iterator::operator++
istreambuf_iterator& operator++();
istreambuf_iterator operator++(int);
istreambuf_iterator::operator->
istreambuf_iterator::streambuf_type
istreambuf_iterator::traits_type
typedef T traits_type;
iterator
iterator_traits
template<class It>
struct iterator_traits {
typedef It::iterator_category iterator_category;
typedef It::value_type value_type;
typedef It::distance_type distance_type;
};
which determine the same types somewhat less directly. You use
these functions as arguments on a function call. Their sole purpose
is to supply a useful template class parameter to the called
function.
operator!=
operator==
operator<
operator<=
operator>
operator>=
operator+
operator-
ostream_iterator
};
ostream_iterator::char_type
typedef E char_type;
ostream_iterator::operator*
ostream_iterator::operator++
ostream_iterator::operator=
The operator inserts val into the output stream associated with the
object, then returns *this.
ostream_iterator::ostream_iterator
ostream_iterator(ostream_type& os);
ostream_iterator(ostream_type& os, const E *delim);
ostream_iterator::ostream_type
ostream_iterator::traits_type
typedef T traits_type;
ostream_iterator::value_type
typedef U value_type;
ostreambuf_iterator
ostreambuf_iterator::char_type
typedef E char_type;
ostreambuf_iterator::failed
ostreambuf_iterator::operator*
ostreambuf_iterator& operator*();
ostreambuf_iterator::operator++
ostreambuf_iterator& operator++();
T1 operator++(int);
ostreambuf_iterator::operator=
ostreambuf_iterator::ostream_type
ostreambuf_iterator::ostreambuf_iterator
ostreambuf_iterator::streambuf_type
ostreambuf_iterator::traits_type
typedef T traits_type;
output_iterator_tag
struct output_iterator_tag {
};
random_access_iterator_tag
struct random_access_iterator_tag
: public bidirectional_iterator_tag {
};
reverse_bidirectional_iterator
template<class BidIt,
class T = iterator_traits<BidIt>::value_type,
reverse_bidirectional_iterator::base
reverse_bidirectional_iterator::iter_type
reverse_bidirectional_iterator::operator*
reverse_bidirectional_iterator::operator++
reverse_bidirectional_iterator& operator++();
reverse_bidirectional_iterator operator++(int);
reverse_bidirectional_iterator::operator--
reverse_bidirectional_iterator& operator--();
reverse_bidirectional_iterator operator--();
reverse_bidirectional_iterator::operator->
reverse_bidirectional_iterator::pointer_type
reverse_bidirectional_iterator::reference_type
reverse_bidirectional_iterator::reverse_bidirectional_iterator
reverse_bidirectional_iterator();
explicit reverse_bidirectional_iterator(BidIt x);
reverse_iterator
template<class RanIt,
class T = iterator_traits<RanIt>::value_type,
class Ref = T&,
class Ptr = T *, class Dist = ptrdiff_t>
class reverse_iterator
: public iterator<random_access_iterator_tag, T, Dist> {
public:
typedef RanIt iter_type;
typedef Ref reference_type;
reverse_iterator::base
reverse_iterator::iter_type
reverse_iterator::operator*
reverse_iterator::operator+
reverse_iterator::operator++
reverse_iterator& operator++();
reverse_iterator operator++(int);
reverse_iterator::operator+=
reverse_iterator::operator-
reverse_iterator::operator--
reverse_iterator& operator--();
reverse_iterator operator--();
reverse_iterator::operator-=
reverse_iterator::operator->
reverse_iterator::operator[]
reverse_iterator::pointer_type
reverse_iterator::reference_type
reverse_iterator::reverse_iterator
reverse_iterator();
explicit reverse_iterator(RanIt x);
<limits>
namespace std {
enum float_round_style;
template<class T>
class numeric_limits;
};
float_round_style
enum float_round_style {
round_indeterminate = -1,
round_toward_zero = 0,
round_to_nearest = 1,
round_toward_infinity = 2,
round_toward_neg_infinity = 3
};
numeric_limits
template<class T>
class numeric_limits {
public:
static const bool has_denorm = false;
static const bool has_denorm_loss = false;
static const bool has_infinity = false;
numeric_limits::denorm_min
The function returns the minimum value for the type (which is the
same as min() if has_denorm is false).
numeric_limits::digits
The member stores the number of radix digits that the type can
represent without change (which is the number of bits other than
any sign bit for a predefined integer type, or the number of
mantissa digits for a predefined floating-point type).
numeric_limits::digits10
The member stores the number of decimal digits that the type can
represent without change.
numeric_limits::epsilon
numeric_limits::has_denorm
numeric_limits::has_denorm_loss
The member stores true for a type that determines whether a value
has lost accuracy because it is delivered as a denormalized result
(too small to represent as a normalized value) or because it is
inexact (not the same as a result not subject to limitations of
exponent range and precision). The latter is an option with IEC 559
floating-point representations that can affect some results.
numeric_limits::has_infinity
The member stores true for a type that has a representation for
positive infinity. True if is_iec559 is true.
numeric_limits::has_quiet_NaN
The member stores true for a type that has a representation for a
quiet NaN, an encoding that is "Not a Number" that does not signal
its presence in an expression. True if is_iec559 is true.
numeric_limits::has_signaling_NaN
The member stores tree for a type that has a representation for a
signaling NaN, an encoding that is ``Not a Number'' which signals
its presence in an expression by reporting an exception. True if
is_iec559 is true.
numeric_limits::infinity
numeric_limits::is_bounded
The member stores true for a type that has a bounded set of
representable values (which is the case for all predefined types).
numeric_limits::is_exact
The member stores true for a type that has exact representations
for all its values (which is the case for all predefined integer
types). A fixed-point or rational representation is also considered
exact, but not a floating-point representation.
numeric_limits::is_iec559
numeric_limits::is_integer
numeric_limits::is_modulo
The member stores true for a type that has a modulo representation,
where all results are reduced modulo some value (which is the case
for all predefined unsigned integer types).
numeric_limits::is_signed
The member stores true for a type that has a signed representation
(which is the case for all predefined floating-point and signed
integer types).
numeric_limits::is_specialized
numeric_limits::max
The function returns the maximum finite value for the type (which
is INT_MAX for type int and FLT_MAX for type float). The return
is meaningful if is_bounded is true.
numeric_limits::max_exponent
The member stores the maximum positive integer such that the type
can represent as a finite value radix raised to that power (which
is the value FLT_MAX_EXP for type float). Meaningful only
floating-point types.
numeric_limits::max_exponent10
The member stores the maximum positive integer such that the type
can represent as a finite value 10 raised to that power (which is
the value FLT_MAX_10_EXP for type float). Meaningful only
floating-point types.
numeric_limits::min
The function returns the minimum normalized value for the type
(which is INT_MIN for type int and FLT_MIN for type float). The
value is meaningful if is_bounded is true or is_signed is false.
numeric_limits::min_exponent
The member stores the minimum negative integer such that the type
can represent as a normalized value radix raised to that power
(which is the value FLT_MIN_EXP for type float). Meaningful only
floating-point types.
numeric_limits::min_exponent10
The member stores the minimum negative integer such that the type
can represent as a normalized value 10 raised to that power (which
is the value FLT_MIN_10_EXP for type float). Meaningful only
floating-point types.
numeric_limits::quiet_NaN
numeric_limits::radix
The member stores the base of the representation for the type
(which is 2 for the predefined integer types, and the base to which
the exponent is raised, or FLT_RADIX, for the predefined floating-
point types).
numeric_limits::round_error
The function returns the maximum rounding error for the type.
numeric_limits::round_style
numeric_limits::signaling_NaN
numeric_limits::tinyness_before
The member stores true for a type that determines whether a value
is "tiny" (too small to represent as a normalized value) before
rounding, an option with IEC 559 floating-point representations
that can affect some results.
numeric_limits::traps
The member stores true for a type that generates some kind of
signal to report certain arithmetic exceptions.
<list>
namespace std {
template<class T, class A>
class list;
// TEMPLATE FUNCTIONS
template<class T, class A>
bool operator==(
const list<T, A>& lhs,
const list<T, A>& rhs);
template<class T, class A>
bool operator!=(
const list<T, A>& lhs,
const list<T, A>& rhs);
template<class T, class A>
bool operator<(
const list<T, A>& lhs,
const list<T, A>& rhs);
template<class T, class A>
bool operator>(
const list<T, A>& lhs,
const list<T, A>& rhs);
template<class T, class A>
bool operator<=(
const list<T, A>& lhs,
const list<T, A>& rhs);
template<class T, class A>
bool operator>=(
const list<T, A>& lhs,
const list<T, A>& rhs);
template<class T, class A>
void swap(
const list<T, A>& lhs,
const list<T, A>& rhs);
};
list
. value_type
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. Note that allocator is not copied when
the object is assigned.
list::allocator_type
typedef A allocator_type;
list::assign
template<class InIt>
void assign(InIt first, InIt last);
template<class Size, class T2>
void assign(Size n, const T2& x = T2());
list::back
reference back();
const_reference back() const;
list::begin
list::clear
list::const_iterator
typedef T1 const_iterator;
list::const_reference
list::const_reverse_iterator
typedef reverse_bidirectional_iterator<const_iterator,
value_type, const_reference, A::const_pointer,
difference_type> const_reverse_iterator;
list::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
list::empty
list::end
list::erase
list::front
reference front();
const_reference front() const;
list::get_allocator
A get_allocator() const;
list::insert
template<class InIt>
void insert(iterator it, InIt first, InIt last);
is replaced by:
list::iterator
typedef T0 iterator;
list::list
All constructors store the allocator object al (or, for the copy
constructor, x.get_allocator()) in allocator and initialize the
controlled sequence. The first constructor specifies an empty
initial controlled sequence. The second constructor specifies a
repetition of n elements of value x. The third constructor
specifies a copy of the sequence controlled by x. The last
constructor specifies the sequence [first, last). None of the
constructors perform any interim reallocations.
template<class InIt>
list(InIt first, InIt last, const A& al = A());
is replaced by:
list::max_size
The member function returns the length of the longest sequence that
the object can control.
list::merge
template<class Pred>
void merge(list& x, Pred pr);
is replaced by:
list::pop_back
void pop_back();
list::push_back
list::pop_front
void pop_front();
list::push_front
list::rbegin
list::reference
list::remove
list::remove_if
templace<class Pred>
void remove_if(Pred pr);
is replaced by:
list::rend
list::resize
list::reverse
void reverse();
list::reverse_iterator
typedef reverse_bidirectional_iterator<iterator,
value_type, reference, A::pointer,
difference_type> reverse_iterator;
list::size
list::size_type
list::sort
void sort();
template<class Pred>
void sort(greater<T> pr);
template<class Pred>
void sort(Pred pr);
is replaced by:
list::splice
list::swap
list::unique
void unique();
void unique(not_equal_to<T> pr);
template<class Pred>
void unique(Pred pr);
is replaced by:
list::value_type
operator!=
operator==
operator<
operator<=
operator>
operator>=
swap
<locale>
namespace std {
class locale;
class ctype_base;
template<class E>
class ctype;
class ctype<char>;
template<class E>
class ctype_byname;
class codecvt_base;
template<class From, class To, class State>
class codecvt;
template<class From, class To, class State>
class codecvt_byname;
template<class E, class InIt>
class num_get;
template<class E, class OutIt>
class num_put;
template<class E>
class numpunct;
template<class E>
class numpunct_byname;
template<class E>
class collate;
template<class E>
class collate_byname;
class time_base;
template<class E, class InIt>
class time_get;
template<class E, class InIt>
class time_get_byname;
template<class E, class OutIt>
class time_put;
template<class E, class OutIt>
class time_put_byname;
class money_base;
template<class E, bool Intl, class InIt>
class money_get;
template<class E, bool Intl, class OutIt>
class money_put;
template<class E, bool Intl>
class moneypunct;
template<class E, bool Intl>
class moneypunct_byname;
class messages_base;
template<class E>
class messages;
template<class E>
class messages_byname;
// TEMPLATE FUNCTIONS
template<class Facet>
bool has_facet(const locale& loc, const Facet *fac);
template<class Facet>
const Facet& use_facet(const locale& loc,
const Facet *fac, bool is_std);
template<class E>
bool isspace(E c, const locale& loc) const;
template<class E>
bool isprint(E c, const locale& loc) const;
template<class E>
bool iscntrl(E c, const locale& loc) const;
template<class E>
bool isupper(E c, const locale& loc) const;
template<class E>
codecvt
codecvt::always_noconv
codecvt::codecvt
codecvt::do_always_noconv
codecvt::do_encoding
codecvt::do_in
codecvt::do_length
codecvt::do_max_length
codecvt::do_out
codecvt::encoding
codecvt::from_type
codecvt::in
codecvt::length
codecvt::max_length
codecvt::out
codecvt::state_type
codecvt::to_type
typedef To to_type;
codecvt_base
class codecvt_base {
public:
enum result {ok, partial, error, noconv};
};
codecvt_byname
collate
template<class E>
class collate : public locale::facet {
public:
typedef E char_type;
typedef basic_string<E> string_type;
collate::char_type
typedef E char_type;
collate::collate
collate::compare
collate::do_compare
If the first sequence compares less than the second sequence, the
function returns -1. If the second sequence compares less, the
function returns +1. Otherwise, the function returns zero.
collate::do_transform
collate::do_hash
collate::hash
collate::string_type
collate::transform
collate_byname
template<class E>
class collate_byname : public collate<E> {
public:
explicit collate_byname(const char *s, size_t refs = 0);
protected:
~collate_byname();
};
ctype
template<class E>
class ctype : public locale::facet, public ctype_base {
public:
typedef E char_type;
explicit ctype(size_t refs = 0);
bool is(mask msk, E ch) const;
const E *is(const E *first, const E *last, mask *dst) const;
const E *scan_is(mask msk, const E *first, const E *last) const;
const E *scan_not(mask msk, const E *first, const E *last) const
E toupper(E ch) const;
const E *toupper(E *first, E *last) const;
E tolower(E ch) const;
const E *tolower(E *first, E *last) const;
E widen(char ch) const;
const char *widen(char *first, char *last, E *dst) const;
char narrow(E ch, char dflt) const;
const E *narrow(const E *first, const E *last,
char dflt, char *dst) const;
static locale::id id;
protected:
~ctype();
virtual bool do_is(mask msk, E ch) const;
virtual const E *do_is(const E *first, const E *last,
mask *dst) const;
virtual const E *do_scan_is(mask msk, const E *first,
const E *last) const;
virtual const E *do_scan_not(mask msk, const E *first,
const E *last) const;
virtual E do_toupper(E ch) const;
virtual const E *do_toupper(E *first, E *last) const;
virtual E do_tolower(E ch) const;
virtual const E *do_tolower(E *first, E *last) const;
virtual E do_widen(char ch) const;
virtual const char *do_widen(char *first, char *last, E *dst) co
virtual char do_narrow(E ch, char dflt) const;
virtual const E *do_narrow(const E *first, const E *last,
char dflt, char *dst) const;
};
All other operations are performed on char values the same as for
specialization ctype<char>.
ctype::char_type
typedef E char_type;
ctype::ctype
ctype::do_is
ctype::do_narrow
ctype::do_scan_is
ctype::do_scan_not
ctype::do_tolower
ctype::do_toupper
ctype::do_widen
ctype::is
The first member function returns do_is(msk, ch). The second member
function returns do_is(first, last, dst).
ctype::narrow
ctype::scan_is
ctype::scan_not
ctype::tolower
ctype::toupper
ctype::widen
ctype<char>
lIts sole public constructor lets you specify tab, the ctype
mask table, and del, the Boolean object that is true if the
array should be deleted when the ctype<char> object is
destroyed -- as well as the usual reference-count parameter
refs.
lThe protected member function table() returns the stored ctype
mask table.
lThe static member object table_size specifies the minimum
number of elements in a ctype mask table.
lThe protected static member function classic_table() returns
the ctype mask table appropriate to the "C" locale.
lThere are no protected virtual member functions do_is,
do_narrow, do_scan_is, do_scan_not, or do_widen. The
corresponding public member functions perform the equivalent
operations themselves.
lThe member functions narrow and widen simply copy elements
unaltered.
ctype_base
class ctype_base {
public:
enum mask;
static const mask space, print, cntrl,
ctype_byname
template<class E>
class ctype_byname : public ctype<E> {
public:
explicit ctype_byname(const char *s, size_t refs = 0);
protected:
~ctype_byname();
};
has_facet
template<class Facet>
bool has_facet(const locale& loc, const Facet *fac);
isalnum
template<class E>
isalpha
template<class E>
bool isalpha(E c, const locale& loc) const;
iscntrl
template<class E>
bool iscntrl(E c, const locale& loc) const;
isdigit
template<class E>
bool isdigit(E c, const locale& loc) const;
isgraph
template<class E>
bool isgraph(E c, const locale& loc) const;
islower
template<class E>
bool islower(E c, const locale& loc) const;
isprint
template<class E>
bool isprint(E c, const locale& loc) const;
ispunct
template<class E>
bool ispunct(E c, const locale& loc) const;
isspace
template<class E>
bool isspace(E c, const locale& loc) const;
isupper
template<class E>
bool isupper(E c, const locale& loc) const;
isxdigit
template<class E>
bool isxdigit(E c, const locale& loc) const;
locale
class locale {
public:
class facet;
class id;
typedef int category;
static const category none, collate, ctype, monetary,
numeric, time, messages, all;
locale();
explicit locale(const char *s);
locale(const locale& x, const locale& y,
category cat);
locale(const locale& x, const char *s, category cat);
bool operator()(const string& lhs,
const string& rhs) const;
string name() const;
bool operator==(const locale& x) const;
bool operator!=(const locale& x) const;
static locale global(const locale& x);
static const locale& classic();
};
You can define an open-ended set of these facets. You can also
construct a locale object that designates an arbitrary number of
facets.
collate<char>
collate<wchar_t>
ctype<char>
ctype<wchar_t>
codecvt<char, char, mbstate_t>
codecvt<wchar_t, char, mbstate_t>
moneypunct<char, false>
moneypunct<wchar_t, false>
moneypunct<char, true>
moneypunct<wchar_t, true>
money_get<char, istreambuf_iterator<char> >
money_get<wchar_t, istreambuf_iterator<wchar_t> >
money_put<char, ostreambuf_iterator<char> >
money_put<wchar_t, ostreambuf_iterator<wchar_t> >
messages<char>
messages<wchar_t>
cout.imbue(locale::empty());
locale::category
The type is a synonym for int, so that it can represent any of the
locale categories. It can also represent a group of constants local
to class locale:
locale::classic
locale::facet
class facet {
protected:
explicit facet(size_t refs = 0);
virtual ~facet();
private:
facet(const facet&) // not defined
void operator=(const facet&) // not defined
};
The member class serves as the base class for all locale facets.
Note that you can neither copy nor assign an object of class facet.
You can construct and destroy objects derived from class
locale::facet, but not objects of the base class proper. Typically,
you construct an object myfac derived from facet when you construct
a locale, as in:
In such cases, the constructor for the base class facet should have
a zero refs argument. When the object is no longer needed, it is
deleted. Thus, you supply a nonzero refs argument only in those
rare cases where you take responsibility for the lifetime of the
object.
locale::global
locale::id
class id {
protected:
id();
private:
id(const id&) // not defined
void operator=(const id&) // not defined
};
locale::locale
locale();
explicit locale(const char *s);
locale(const locale& x, const locale& y,
category cat);
locale(const locale& x, const char *s, category cat);
template<class Facet>
locale(const locale& x, Facet *fac);
template<class Facet>
locale(const locale& x, const locale& y);
locale::name
locale::operator!=
locale::operator()
is replaced by:
locale::operator==
The member function returns true only if *this and x are copies of
the same locale or have the same name (other than "*").
messages
template<class E>
class messages : public locale::facet, public messages_base {
public:
typedef E char_type;
typedef basic_string<E> string_type;
explicit messages(size_t refs = 0);
catalog open(const string& name,
const locale& loc) const;
string_type get(catalog cat, int set, int msg,
const string_type& dflt) const;
void close(catalog cat) const;
static locale::id id;
protected:
~messages();
virtual catalog do_open(const string& name,
const locale& loc) const;
virtual string_type do_get(catalog cat, int set, int msg,
const string_type& dflt) const;
virtual void do_close(catalog cat) const;
};
messages::char_type
typedef E char_type;
messages::close
messages::do_close
messages::do_get
messages::do_open
messages::get
messages::messages
messages::open
messages::string_type
messages_base
class messages_base {
typedef int catalog;
};
messages_byname
template<class E>
class messages_byname : public messages<E> {
public:
explicit messages_byname(const char *s, size_t refs = 0);
protected:
~messages_byname();
};
money_base
class money_base {
enum part {none, sign, space,
symbol, value};
struct pattern {
char field[4];
};
};
money_get
template<class E,
class InIt = istreambuf_iterator<E> >
class money_get : public locale::facet {
public:
typedef E char_type;
typedef InIt iter_type;
typedef basic_string<E> string_type;
explicit money_get(size_t refs = 0);
iter_type get(iter_type first, iter_type last, bool intl,
ios_base& x, ios_base::iostate& st, long double& val) const;
iter_type get(iter_type first, iter_type last, bool intl,
ios_base& x, ios_base::iostate& st, string_type& val) const;
static locale::id id;
protected:
~money_get();
virtual iter_type do_get(iter_type first, iter_type last, bool i
ios_base& x, ios_base::iostate& st, string_type& val) const;
virtual iter_type do_get(iter_type first, iter_type last, bool i
ios_base& x, ios_base::iostate& st, long double& val) const;
};
money_get::char_type
typedef E char_type;
money_get::do_get
money_get::get
money_get::iter_type
money_get::money_get
money_get::string_type
money_put
template<class E,
class OutIt = ostreambuf_iterator<E> >
class money_put : public locale::facet {
public:
typedef E char_type;
typedef OutIt iter_type;
typedef basic_string<E> string_type;
explicit money_put(size_t refs = 0);
iter_type put(iter_type next, bool intl, ios_base& x,
E fill, long double& val) const;
iter_type put(iter_type next, bool intl, ios_base& x,
E fill, string_type& val) const;
static locale::id id;
protected:
~money_put();
virtual iter_type do_put(iter_type next, bool intl,
ios_base& x, E fill, string_type& val) const;
virtual iter_type do_put(iter_type next, bool intl,
ios_base& x, E fill, long double& val) const;
};
money_put::char_type
typedef E char_type;
money_put::do_put
money_put::put
money_put::iter_type
money_put::money_put
money_put::string_type
moneypunct
The const static object intl stores the value of the template
parameter Intl.
moneypunct::char_type
typedef E char_type;
moneypunct::curr_symbol
moneypunct::decimal_point
E decimal_point() const;
moneypunct::do_curr_symbol
moneypunct::do_decimal_point
E do_decimal_point() const;
moneypunct::do_frac_digits
moneypunct::do_grouping
moneypunct::do_neg_format
moneypunct::do_negative_sign
moneypunct::do_pos_format
moneypunct::do_positive_sign
moneypunct::do_thousands_sep
E do_thousands_sep() const;
moneypunct::frac_digits
moneypunct::grouping
moneypunct::moneypunct
moneypunct::neg_format
moneypunct::negative_sign
moneypunct::pos_format
moneypunct::positive_sign
moneypunct::string_type
moneypunct::thousands_sep
E thousands_sep() const;
moneypunct_byname
public:
explicit moneypunct_byname(const char *s, size_t refs = 0);
protected:
~moneypunct_byname();
};
num_get
num_get::char_type
typedef E char_type;
num_get::do_get
The integer input field is converted by the same rules used by the
scan functions for matching and converting a series of char
from a file. (Each such char element is assumed to map to
equivalent element of type E by a simple, one-to-one, mapping.) The
equivalent scan conversion specification is determined as follows:
behaves the same as the third, except that the equivalent scan
conversion specifier is Lf.
behaves the same as the first, except that the equivalent scan
conversion specifier is p.
num_get::get
num_get::iter_type
num_get::num_get
num_put
num_put::char_type
typedef E char_type;
num_put::do_put
The integer output field is generated by the same rules used by the
print functions for generating a series of char elements to a
(Each such char element is assumed to map to an equivalent element
type E by a simple, one-to-one, mapping.) Where a print function
pads a field with either spaces or the digit 0, however, do_put
instead uses fill. The equivalent print conversion specification is
determined as follows:
Finally:
behaves the same as the third, except that the qualifier l in the
conversion specification is replaced with L.
num_put::put
num_put::iter_type
num_put::num_put
numpunct
numpunct::char_type
typedef E char_type;
numpunct::decimal_point
E decimal_point() const;
numpunct::do_decimal_point
E do_decimal_point() const;
numpunct::do_falsename
numpunct::do_grouping
numpunct::do_thousands_sep
E do_thousands_sep() const;
numpunct::do_truename
numpunct::falsename
numpunct::grouping
numpunct::numpunct
numpunct::string_type
numpunct::thousands_sep
E thousands_sep() const;
numpunct::truename
numpunct_byname
template<class E>
class numpunct_byname : public numpunct<E> {
public:
explicit numpunct_byname(const char *s, size_t refs = 0);
protected:
~numpunct_byname();
};
time_base
class time_base {
public:
enum dateorder {no_order, dmy, mdy, ymd, ydm};
};
time_get
time_get::char_type
typedef E char_type;
time_get::date_order
time_get::do_date_order
time_get::do_get_date
In this implementation, the date input field has the form MMM DD,
YYYY, where:
time_get::do_get_month
time_get::do_get_time
In this implementation, the time input field has the form HH:MM:SS,
where:
time_get::do_get_weekday
time_get::do_get_year
time_get::get_date
time_get::get_month
time_get::get_time
time_get::get_weekday
time_get::get_year
time_get::iter_type
time_get::time_get
time_get_byname
time_put
E.
time_put::char_type
typedef E char_type;
time_put::do_put
time_put::put
time_put::iter_type
time_put::time_put
(refs).
time_put_byname
tolower
template<class E>
E tolower(E c, const locale& loc) const;
toupper
template<class E>
E toupper(E c, const locale& loc) const;
use_facet
template<class Facet>
const Facet& use_facet(const locale& loc,
const Facet *fac, bool make_it);
<map>
namespace std {
template<class Key, class T, class Pred, class A>
class map;
map
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. Note that allocator is not copied when
the object is assigned.
map::allocator_type
typedef A allocator_type;
map::begin
map::clear
map::const_iterator
typedef T1 const_iterator;
map::const_reference
map::const_reverse_iterator
typedef reverse_bidirectional_iterator<const_iterator,
value_type, const_reference, A::const_pointer,
difference_type> const_reverse_iterator;
map::count
map::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
map::empty
map::end
map::equal_range
map::erase
The third member function removes the elements with sort keys in
the range [lower_bound(key), upper_bound(key)). It returns the
number of elements it removes.
map::find
map::get_allocator
A get_allocator() const;
map::insert
template<class InIt>
void insert(InIt first, InIt last);
is replaced by:
map::iterator
typedef T0 iterator;
map::key_comp
map::key_compare
The type describes a function object that can compare two sort keys
to determine the relative order of any two elements in the
controlled sequence.
map::key_type
The type describes the sort key object stored in each element of
the controlled sequence.
map::lower_bound
map::map
template<class InIt>
map(InIt first, InIt last,
const Pred& comp = Pred(), const A& al = A());
is replaced by:
map::max_size
The member function returns the length of the longest sequence that
the object can control.
map::operator[]
map::rbegin
map::reference
map::referent_type
typedef T referent_type;
map::rend
map::reverse_iterator
typedef reverse_bidirectional_iterator<iterator,
value_type, reference, A::pointer,
difference_type> reverse_iterator;
map::size
map::size_type
map::swap
map::upper_bound
map::value_comp
map::value_compare
class value_compare
: public binary_function<value_type, value_type, bool> {
public:
bool operator()(const value_type& x, const value_type& y)
{return (comp(x.first, x.second)); }
protected:
value_compare(key_compare pr)
: comp(pr) {}
key_compare comp;
};
The type describes a function object that can compare the sort keys
in two elements to determine their relative order in the controlled
map::value_type
multimap
A get_allocator() const;
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. Note that allocator is not copied when
the object is assigned.
multimap::allocator_type
typedef A allocator_type;
multimap::begin
multimap::clear
multimap::const_reference
multimap::const_iterator
typedef T1 const_iterator;
multimap::count
multimap::const_reverse_iterator
typedef reverse_bidirectional_iterator<const_iterator,
value_type, const_reference, A::const_pointer,
difference_type> const_reverse_iterator;
multimap::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
multimap::empty
multimap::end
multimap::equal_range
multimap::erase
The third member removes the elements with sort keys in the range
[lower_bound(key), upper_bound(key)). It returns the number of
elements it removes.
multimap::find
multimap::get_allocator
A get_allocator() const;
multimap::insert
template<class InIt>
void insert(InIt first, InIt last);
is replaced by:
multimap::iterator
typedef T0 iterator;
multimap::key_comp
multimap::key_compare
The type describes a function object that can compare two sort keys
to determine the relative order of any two elements in the
controlled sequence.
multimap::key_type
The type describes the sort key object stored in each element of
the controlled sequence.
multimap::lower_bound
multimap::max_size
The member function returns the length of the longest sequence that
the object can control.
multimap::multimap
template<class InIt>
multimap(InIt first, InIt last,
const Pred& comp = Pred(), const A& al = A());
is replaced by:
multimap::rbegin
multimap::reference
multimap::referent_type
typedef T referent_type;
multimap::rend
multimap::reverse_iterator
typedef reverse_bidirectional_iterator<iterator,
value_type, reference, A::pointer,
difference_type> reverse_iterator;
multimap::size
multimap::size_type
multimap::swap
multimap::upper_bound
multimap::value_comp
multimap::value_compare
class value_compare
: public binary_function<value_type, value_type, bool> {
public:
bool operator()(const value_type& x, const value_type& y)
{return (comp(x.first, x.second)); }
protected:
value_compare(key_compare pr)
: comp(pr) {}
key_compare comp;
};
The type describes a function object that can compare the sort keys
in two elements to determine their relative order in the controlled
sequence. The function object stores an object comp of type
key_type. The member function operator() uses this object to
compare the sort-key components of two elements.
multimap::value_type
operator!=
operator==
operator<
operator<=
operator>
operator>=
swap
<memory>
namespace std {
// TEMPLATE CLASSES
template<class T>
class allocator;
class allocator<void>;
template<class FwdIt, class T>
class raw_storage_iterator;
template<class T>
class auto_ptr;
// TEMPLATE OPERATORS
template<class T>
bool operator==(allocator<T>& lhs,
allocator<T>& rhs);
template<class T>
bool operator!=(allocator<T>& lhs,
allocator<T>& rhs);
template<class T>
void operator delete(void *p, size_t n, allocator& al);
template<class T>
void *operator new(size_t n, allocator& al);
// TEMPLATE FUNCTIONS
template<class T>
pair<T *, ptrdiff_t> get_temporary_buffer(ptrdiff_t n, T *);
template<class T>
void return_temporary_buffer(T *p);
template<class InIt, class FwdIt>
FwdIt uninitialized_copy(InIt first, InIt last, FwdIt result);
template<class FwdIt, class T>
void uninitialized_fill(FwdIt first, FwdIt last, const T& x);
template<class FwdIt, class Size, class T>
allocator
template<class T>
class allocator {
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
pointer address(reference x) const;
const_pointer address(const_reference x) const;
allocator();
allocator<T>& operator=(const allocator<T>);
pointer allocate(size_type n, const void *hint);
void deallocate(pointer p, size_type n);
void construct(pointer p, const T& val);
void destroy(pointer p);
size_type max_size() const;
};
These types specify the form that pointers and references must take
for allocated elements. (allocator::types<T>::pointer is not
necessarily the same as T * for all allocator objects, even though
it has this obvious definition for class allocator.)
template<class U>
struct rebind {
typedef allocator<U> other;
};
allocator::address
allocator::allocate
template<class U>
pointer allocate(size_type n, const U *hint);
is replaced by:
allocator::allocator
allocator();
allocator(const allocator<T>);
template<class U>
allocator(const allocator<U>);
is replaced by:
allocator(const allocator<T>);
allocator::const_pointer
The pointer type describes an object p that can designate, via the
expression *p, any const object that an object of template class
allocator can allocate.
allocator::const_reference
allocator::construct
allocator::deallocate
allocator::destroy
allocator::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in a sequence
that an object of template class allocator can allocate.
allocator::max_size
allocator::operator=
template<class U>
allocator<T>& operator=(const allocator<U>);
is replaced by:
allocator::pointer
typedef T *pointer;
The pointer type describes an object p that can designate, via the
expression *p, any object that an object of template class
allocator can allocate.
allocator::reference
allocator::size_type
allocator::value_type
typedef T value_type;
allocator<void>
class allocator<void> {
typedef void *pointer;
typedef const void *const_pointer;
typedef void value_type;
allocator();
template<class U>
allocator(const allocator<U>);
template<class U>
operator=(const allocator<U>);
};
auto_ptr
template<class T>
class auto_ptr {
public:
typedef T element_type;
explicit auto_ptr(T *p = 0) throw();
auto_ptr(const auto_ptr<T>& rhs) throw();
auto_ptr<T>& operator=(auto_ptr<T>& rhs) throw();
~auto_ptr();
T& operator*() const throw();
T *operator->() const throw();
T *get() const throw();
T *release() const throw();
};
auto_ptr::auto_ptr
template<class U>
auto_ptr(const auto_ptr(auto_ptr<U>& rhs) throw();
is replaced by:
auto_ptr::~auto_ptr
~auto_ptr();
auto_ptr::element_type
typedef T element_type;
auto_ptr::get
auto_ptr::operator=
template<class U>
auto_ptr<T>& operator=(auto_ptr<U>& rhs) throw();
is replaced by:
auto_ptr::operator*
auto_ptr::operator->
auto_ptr::release
T *release() throw();
get_temporary_buffer
template<class T>
pair<T *, ptrdiff_t> get_temporary_buffer(ptrdiff_t n, T *);
template<class T>
pair<T *, ptrdiff_t> get_temporary_buffer(ptrdiff_t n);
is replaced by:
template<class T>
pair<T *, ptrdiff_t> get_temporary_buffer(ptrdiff_t n, T *);
operator!=
template<class T>
bool operator!=(allocator<T>& lhs,
allocator<T>& rhs);
operator==
template<class T>
bool operator==(allocator<T>& lhs,
allocator<T>& rhs);
operator delete
template<class T>
void operator delete(void *p, size_t n, allocator<T>& al);
operator new
template<class T>
void *operator new(size_t n, allocator<T>& al);
raw_storage_iterator
raw_storage_iterator::element_type
typedef T element_type;
raw_storage_iterator::iterator_type
raw_storage_iterator::operator*
raw_storage_iterator::operator=
raw_storage_iterator::operator++
raw_storage_iterator::raw_storage_iterator
return_temporary_buffer
template<class T>
void return_temporary_buffer(T *p);
uninitialized_copy
uninitialized_fill
uninitialized_fill_n
<numeric>
namespace std {
template<class InIt, class T>
T accumulate(InIt first, InIt last, T val);
template<class InIt, class T, class Pred>
T accumulate(InIt first, InIt last, T val, Pred pr);
template<class InIt1, class InIt2, class T>
T product(InIt1 first1, InIt1 last1,
Init2 first2, T val);
template<class InIt1, class InIt2, class T,
class Pred1, class Pred2>
T product(InIt1 first1, InIt1 last1,
Init2 first2, T val, Pred1 pr1, Pred2 pr2);
template<class InIt, class OutIt>
OutIt partial_sum(InIt first, InIt last,
OutIt result);
template<class InIt, class OutIt, class Pred>
OutIt partial_sum(InIt first, InIt last,
OutIt result, Pred pr);
template<class InIt, class OutIt>
accumulate
The first template function repeatedly replaces val with val + *I,
for each value of the InIt iterator I in the interval [first,
last). It then returns val.
adjacent_difference
inner_product
The first template function repeatedly replaces val with val + (*I1
* *I2), for each value of the InIt1 iterator I1 in the interval
[first1, last2). In each case, the InIt2 iterator I2 equals first2
+ (I1 - first1). The function returns val.
partial_sum
<ostream>
namespace std {
template<class E, class T = char_traits<E> >
class basic_ostream;
typedef basic_ostream<char, char_traits<char> > ostream;
typedef basic_ostream<wchar_t, char_traits<wchar_t> > wostream;
// INSERTERS
template<class E, class T>
basic_ostream<E, T>& operator<<(basic_ostream<E, T> os, cons
template<class E, class T>
basic_ostream<E, T>& operator<<(basic_ostream<E, T> os, E c)
template<class T>
basic_ostream<char, T>& operator<<(basic_ostream<char, T> os
template<class T>
basic_ostream<char, T>& operator<<(basic_ostream<char, T> os
template<class T>
basic_ostream
basic_ostream::basic_ostream
basic_ostream::flush
basic_ostream& flush();
basic_ostream::operator<<
basic_ostream& operator<<(
basic_ostream& (*pf)(basic_ostream&));
basic_ostream& operator<<(
basic_ios<E, T>& (*pf)(basic_ios<E, T>&));
basic_ostream& operator<<(
ios_base<E, T>& (*pf)(ios_base<E, T>&));
basic_ostream& operator<<(
basic_streambuf<E, T> *sb);
basic_ostream& operator<<(const char *s);
basic_ostream& operator<<(char c);
basic_ostream& operator<<(bool n);
basic_ostream& operator<<(short n);
basic_ostream& operator<<(unsigned short n);
basic_ostream& operator<<(int n);
basic_ostream& operator<<(unsigned int n);
basic_ostream& operator<<(long n);
basic_ostream& operator<<(unsigned long n);
basic_ostream& operator<<(float n);
basic_ostream& operator<<(double n);
basic_ostream& operator<<(long double n);
basic_ostream& operator<<(void *n);
The function:
basic_ostream& operator<<(
basic_streambuf<E, T> *sb);
The function:
The function:
The function:
The functions:
The functions:
basic_ostream::opfx
bool opfx();
basic_ostream::osfx
void osfx();
basic_ostream::put
basic_ostream::seekp
basic_ostream::sentry
class sentry {
public:
explicit sentry(basic_ostream<E, T>& os);
operator bool() const;
};
basic_ostream::tellp
pos_type tellp();
basic_ostream::write
endl
ends
flush
operator<<
template<class T>
basic_ostream<char, T>& operator<<(basic_ostream<char, T> os, co
template<class T>
basic_ostream<char, T>& operator<<(basic_ostream<char, T> os, si
template<class T>
basic_ostream<char, T>& operator<<(basic_ostream<char, T> os, co
template<class T>
basic_ostream<char, T>& operator<<(basic_ostream<char, T> os, un
ostream
wostream
<queue>
namespace std {
template<class T, class Cont>
class queue;
template<class T, class Cont, class Pred>
class priority_queue;
// TEMPLATE FUNCTIONS
template<class T, class Cont>
bool operator==(const queue<T, Cont>& lhs,
const queue<T, Cont>&);
template<class T, class Cont>
bool operator!=(const queue<T, Cont>& lhs,
const queue<T, Cont>&);
template<class T, class Cont>
bool operator<(const queue<T, Cont>& lhs,
const queue<T, Cont>&);
template<class T, class Cont>
bool operator>(const queue<T, Cont>& lhs,
const queue<T, Cont>&);
template<class T, class Cont>
operator!=
operator==
operator<
operator<=
operator>
operator>=
priority_queue
template<class T,
class Cont = vector<T>,
class Pred = less<Cont::value_type> >
class priority_queue {
public:
typedef Cont::allocator_type allocator_type;
typedef Cont::value_type value_type;
typedef Cont::size_type size_type;
explicit priority_queue(const Pred& pr = Pred(),
const allocator_type& al = allocator_type());
priority_queue(const value_type *first, const value_type *last,
const Pred& pr = Pred(), const allocator_type& al = allocato
bool empty() const;
size_type size() const;
allocator_type get_allocator() const;
value_type& top();
const value_type& top() const;
void push(const value_type& x);
void pop();
protected:
Cont c;
Pred comp;
};
typedef T value_type;
typedef T0 size_type;
Cont(const A& al);
Cont(InIt first, InIt last, const allocator_type& al);
bool empty() const;
size_type size() const;
allocator_type get_allocator() const;
const value_type& front() const;
value_type& front();
void push_back(const value_type& x);
void pop_back();
priority_queue::allocator_type
priority_queue::empty
priority_queue::get_allocator
priority_queue::pop
void pop();
priority_queue::priority_queue
template<class InIt>
priority_queue(InIt first, InIt last,
const Pred& pr = Pred(), const allocator_type& al = allocato
is replaced by:
priority_queue::push
priority_queue::size
priority_queue::size_type
priority_queue::top
value_type& top();
const value_type& top() const;
priority_queue::value_type
queue
template<class T,
class Cont = deque<T> >
class queue {
public:
typedef Cont::allocator_type allocator_type;
typedef Cont::value_type value_type;
typedef Cont::size_type size_type;
explicit queue(const allocator_type& al = allocator_type()) cons
bool empty() const;
size_type size() const;
allocator_type get_allocator() const;
value_type& top();
const value_type& top() const;
void push(const value_type& x);
void pop();
protected:
Cont c;
};
typedef T value_type;
typedef T0 size_type;
Cont(const allocator_type& al);
bool empty() const;
size_type size() const;
allocator_type get_allocator() const;
value_type& front();
const value_type& front() const;
value_type& back();
const value_type& back() const;
void push_back(const value_type& x);
void pop_front();
queue::allocator_type
queue::back
value_type& back();
const value_type& back() const;
queue::empty
queue::front
value_type& front();
queue::get_allocator
queue::pop
void pop();
queue::push
queue::queue
queue::size
queue::size_type
queue::top
value_type& top();
const value_type& top() const;
queue::value_type
<set>
namespace std {
template<class Key, class Pred, class A>
class set;
template<class Key, class Pred, class A>
class multiset;
// TEMPLATE FUNCTIONS
template<class Key, class Pred, class A>
bool operator==(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator==(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator!=(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator!=(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<=(
const set<Key, Pred, A>& lhs,
const set<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator<=(
const multiset<Key, Pred, A>& lhs,
const multiset<Key, Pred, A>& rhs);
template<class Key, class Pred, class A>
bool operator>=(
multiset
allocator_type . begin .
clear . const_iterator . const_reference .
const_reverse_iterator . count . difference_type . empty . end .
equal_range . erase . find . get_allocator . insert . iterator .
key_comp . key_compare .
key_type . lower_bound . max_size .
multiset . rbegin reference
. . rend . reverse_iterator . size .
size_type . swap . upper_bound . value_comp . value_compare .
value_type
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. Note that allocator is not copied when
the object is assigned.
multiset::allocator_type
yypedef A allocator_type;
multiset::begin
multiset::clear
multiset::const_iterator
typedef T1 const_iterator;
multiset::const_reference
multiset::const_reverse_iterator
typedef reverse_bidirectional_iterator<const_iterator,
value_type, const_reference, A::const_pointer,
difference_type> const_reverse_iterator;
multiset::count
multiset::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
multiset::empty
multiset::end
multiset::equal_range
pair<const_iterator, const_iterator>
equal_range(const Key& key) const;
multiset::erase
The third member removes the elements with sort keys in the range
[lower_bound(key), upper_bound(key)). It returns the number of
elements it removes.
multiset::find
multiset::get_allocator
A get_allocator() const;
multiset::insert
template<class InIt>
void insert(InIt first, InIt last);
is replaced by:
multiset::iterator
typedef T0 iterator;
multiset::key_comp
multiset::key_compare
The type describes a function object that can compare two sort keys
to determine the relative order of any two elements in the
controlled sequence.
multiset::key_type
The type describes the sort key object that constitutes each
element of the controlled sequence.
multiset::lower_bound
multiset::max_size
The member function returns the length of the longest sequence that
the object can control.
multiset::multiset
template<class InIt>
multiset(InIt first, InIt last,
const Pred& comp = Pred(), const A& al = A());
is replaced by:
multiset::rbegin
multiset::reference
multiset::rend
multiset::reverse_iterator
typedef reverse_bidirectional_iterator<iterator,
value_type, reference, A::pointer,
difference_type> reverse_iterator;
multiset::size
multiset::size_type
multiset::swap
multiset::upper_bound
multiset::value_comp
multiset::value_compare
The type describes a function object that can compare two elements
as sort keys to determine their relative order in the controlled
sequence.
multiset::value_type
operator!=
operator==
operator<
operator<=
operator>
operator>=
set
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. Note that allocator is not copied when
the object is assigned.
set::allocator_type
typedef A allocator_type;
set::begin
set::clear
set::const_iterator
typedef T1 const_iterator;
set::const_reference
set::const_reverse_iterator
typedef reverse_bidirectional_iterator<const_iterator,
value_type, const_reference, A::const_pointer,
difference_type> const_reverse_iterator;
set::count
set::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
set::empty
set::end
set::equal_range
pair<const_iterator, const_iterator>
equal_range(const Key& key) const;
set::erase
The third member removes the elements with sort keys in the range
[lower_bound(key), upper_bound(key)). It returns the number of
elements it removes.
set::find
set::get_allocator
A get_allocator() const;
set::insert
template<class InIt>
void insert(InIt first, InIt last);
is replaced by:
set::iterator
typedef T0 iterator;
set::key_comp
set::key_compare
The type describes a function object that can compare two sort keys
to determine the relative order of any two elements in the
controlled sequence.
set::key_type
The type describes the sort key object that constitutes each
element of the controlled sequence.
set::lower_bound
set::max_size
The member function returns the length of the longest sequence that
the object can control.
set::rbegin
set::reference
set::rend
set::reverse_iterator
typedef reverse_bidirectional_iterator<iterator,
value_type, reference, A::pointer,
difference_type> reverse_iterator;
set::set
template<class InIt>
set(InIt first, InIt last,
is replaced by:
set::size
set::size_type
set::swap
set::upper_bound
set::value_comp
set::value_compare
The type describes a function object that can compare two elements
as sort keys to determine their relative order in the controlled
sequence.
set::value_type
swap
<sstream>
namespace std {
template<class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_stringbuf;
typedef basic_stringbuf<char> stringbuf;
typedef basic_stringbuf<wchar_t> wstringbuf;
template<class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_istringstream;
typedef basic_istringstream<char> istringstream;
typedef basic_istringstream<wchar_t> wistringstream;
template<class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_ostringstream;
typedef basic_ostringstream<char> ostringstream;
typedef basic_ostringstream<wchar_t> wostringstream;
template<class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_stringstream;
typedef basic_stringstream<char> stringstream;
typedef basic_stringstream<wchar_t> wstringstream;
};
basic_stringbuf
template <class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_stringbuf {
public:
basic_stringbuf(ios_base::openmode mode =
ios_base::in | ios_base::out);
basic_stringbuf(basic_string<E, T, A>& x,
ios_base::openmode mode = ios_base::in | ios_base::out);
basic_string<E, T, A> str() const;
void str(basic_string<E, T, A>& x);
protected:
virtual pos_type seekoff(off_type off, ios_base::seekdir way,
ios_base::openmode mode = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type sp,
ios_base::openmode mode = ios_base::in | ios_base::out);
virtual int_type underflow();
virtual int_type pbackfail(int_type c = T::eof());
virtual int_type overflow(int_type c = T::eof());
};
basic_stringbuf::basic_stringbuf
basic_stringbuf(ios_base::openmode mode =
ios_base::in | ios_base::out);
basic_stringbuf(basic_string<E, T, A>& x,
ios_base::openmode mode = ios_base::in | ios_base::out);
basic_stringbuf::overflow
basic_stringbuf::pbackfail
basic_stringbuf::seekoff
basic_stringbuf::seekpos
basic_stringbuf::str
basic_stringbuf::underflow
basic_istringstream
template <class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_istringstream : public basic_istream<E, T> {
public:
explicit basic_istringstream(ios_base::openmode mode = ios_base:
explicit basic_istringstream(const basic_string<E, T, A>& x,
ios_base::openmode mode = ios_base::in);
basic_stringbuf<E, T, A> *rdbuf() const;
basic_string<E, T, A>& str();
void str(const basic_string<E, T, A>& x);
};
basic_istringstream::basic_istringstream
basic_istringstream::rdbuf
basic_istringstream::str
basic_ostringstream
template <class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_ostringstream : public basic_ostream<E, T> {
public:
explicit basic_ostringstream(ios_base::openmode mode = ios_base:
explicit basic_ostringstream(const basic_string<E, T, A>& x,
ios_base::openmode mode = ios_base::out);
basic_stringbuf<E, T, A> *rdbuf() const;
basic_string<E, T, A>& str();
void str(const basic_string<E, T, A>& x);
};
basic_ostringstream::basic_ostringstream
basic_ostringstream::rdbuf
basic_ostringstream::str
basic_stringstream
template <class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_stringstream : public basic_iostream<E, T> {
public:
explicit basic_stringstream(ios_base::openmode mode = ios_base::
explicit basic_stringstream(const basic_string<E, T, A>& x,
ios_base::openmode mode = ios_base::in | ios_base::out);
basic_stringbuf<E, T, A> *rdbuf() const;
basic_string<E, T, A>& str();
void str(const basic_string<E, T, A>& x);
};
basic_stringstream::basic_stringstream
basic_stringstream::rdbuf
basic_stringstream::str
istringstream
ostringstream
stringbuf
stringstream
wistringstream
wostringstream
wstringbuf
wstringstream
<stack>
namespace std {
template<class T, class Cont>
class stack;
// TEMPLATE FUNCTIONS
template<class T, class Cont>
bool operator==(const stack<T, Cont>& lhs,
const stack<T, Cont>&);
template<class T, class Cont>
bool operator!=(const stack<T, Cont>& lhs,
const stack<T, Cont>&);
template<class T, class Cont>
bool operator<(const stack<T, Cont>& lhs,
const stack<T, Cont>&);
template<class T, class Cont>
bool operator>(const stack<T, Cont>& lhs,
const stack<T, Cont>&);
template<class T, class Cont>
bool operator<=(const stack<T, Cont>& lhs,
const stack<T, Cont>&);
template<class T, class Cont>
bool operator>=(const stack<T, Cont>& lhs,
const stack<T, Cont>&);
};
operator!=
operator==
operator<
operator<=
operator>
operator>=
stack
template<class T,
class Cont = deque<T> >
class stack {
public:
typedef Cont::allocator_type allocator_type;
typedef Cont::value_type value_type;
typedef Cont::size_type size_type;
explicit stack(const allocator_type& al = allocator_type()) cons
bool empty() const;
size_type size() const;
allocator_type get_allocator() const;
value_type& top();
const value_type& top() const;
void push(const value_type& x);
void pop();
protected:
Cont c;
};
typedef T value_type;
typedef T0 size_type;
Cont(const allocator_type& al);
bool empty() const;
size_type size() const;
allocator_type get_allocator() const;
value_type& back();
const value_type& back() const;
void push_back(const value_type& x);
void pop_back();
stack::allocator_type
stack::empty
stack::get_allocator
stack::pop
void pop();
stack::push
stack::size
stack::size_type
stack::stack
stack::top
value_type& top();
const value_type& top() const;
stack::value_type
<stdexcept>
namespace std {
class logic_error;
class domain_error;
class invalid_argument;
class length_error;
class out_of_range;
class runtime_error;
class range_error;
class overflow_error;
class underflow_error;
};
domain_error
The class serves as the base class for all exceptions thrown to
report a domain error. The value returned by what() is
what_arg.data().
invalid_argument
The class serves as the base class for all exceptions thrown to
report an invalid argument. The value returned by what() is
what_arg.data().
length_error
The class serves as the base class for all exceptions thrown to
report an attempt to generate an object too long to be specified.
The value returned by what() is what_arg.data().
logic_error
The class serves as the base class for all exceptions thrown to
report errors presumably detectable before the program executes,
such as violations of logical preconditions. The value returned by
what() is what_arg.data().
out_of_range
The class serves as the base class for all exceptions thrown to
report an argument that is out of its valid range. The value
returned by what() is what_arg.data().
overflow_error
The class serves as the base class for all exceptions thrown to
report an arithmetic overflow. The value returned by what() is
what_arg.data().
range_error
The class serves as the base class for all exceptions thrown to
report a range error. The value returned by what() is what_arg.data
().
runtime_error
The class serves as the base class for all exceptions thrown to
report errors presumably detectable only when the program executes.
The value returned by what() is what_arg.data().
underflow_error
The class serves as the base class for all exceptions thrown to
report an arithmetic underflow. The value returned by what() is
what_arg.data().
<streambuf>
namespace std {
template<class E, class T = char_traits<E> >
class basic_streambuf;
typedef basic_streambuf<char, char_traits<char> > streambuf;
typedef basic_streambuf<wchar_t, char_traits<wchar_t> > wstreamb
};
basic_streambuf
the end pointer, you can store an element at the write position
designated by the next pointer.
lFor an input buffer, if the next pointer compares less than the
end pointer, you can read an element at the read position
designated by the next pointer.
lFor an input buffer, if the beginning pointer compares less
than the next pointer, you can put back an element at the
putback position designated by the decremented next pointer.
basic_streambuf::basic_streambuf
basic_streambuf();
basic_streambuf::char_type
typedef E char_type;
basic_streambuf::eback
E *eback() const;
basic_streambuf::egptr
E *egptr() const;
The member function returns a pointer just past the end of the
input buffer.
basic_streambuf::epptr
E *epptr() const;
The member function returns a pointer just past the end of the
output buffer.
basic_streambuf::gbump
The member function adds n to the next pointer for the input
buffer.
basic_streambuf::getloc
basic_streambuf::gptr
E *gptr() const;
basic_streambuf::imbue
basic_streambuf::in_avail
streamsize in_avail();
basic_streambuf::int_type
basic_streambuf::off_type
basic_streambuf::overflow
basic_streambuf::pbackfail
basic_streambuf::pbase
E *pbase() const;
basic_streambuf::pbump
The member function adds n to the next pointer for the output
buffer.
basic_streambuf::pos_type
basic_streambuf::pptr
E *pptr() const;
basic_streambuf::pubimbue
The member function stores loc in the locale object, calls imbue(),
and then returns the previous value stored in the locale object.
basic_streambuf::pubseekoff
basic_streambuf::pubseekpos
basic_streambuf::pubsetbuf
basic_streambuf::pubsync
int pubsync();
basic_streambuf::sbumpc
int_type sbumpc();
basic_streambuf::seekoff
basic_streambuf::seekpos
basic_streambuf::setbuf
basic_streambuf::setg
basic_streambuf::setp
basic_streambuf::sgetc
int_type sgetc();
basic_streambuf::sgetn
basic_streambuf::showmanyc
basic_streambuf::snextc
int_type snextc();
basic_streambuf::sputbackc
basic_streambuf::sputc
basic_streambuf::sputn
basic_streambuf::sungetc
int_type sungetc();
basic_streambuf::sync
basic_streambuf::traits_type
typedef T traits_type;
basic_streambuf::uflow
basic_streambuf::underflow
do so in various ways:
basic_streambuf::xsgetn
basic_streambuf::xsputn
streambuf
wstreambuf
<string>
namespace std {
// TEMPLATE CLASSES
template<class E>
struct char_traits;
struct char_traits<char>;
struct char_traits<wchar_t>;
template<class E,
class T = char_traits<E>,
class A = allocator<E> >
class basic_string;
typedef basic_string<char> string;
typedef basic_string>wchar_t> wstring;
// TEMPLATE FUNCTIONS
template<class E, class T, class A>
basic_string<E, T, A> operator+(
const basic_string<E, T, A>& lhs,
const basic_string<E, T, A>& rhs);
template<class E, class T, class A>
basic_string<E, T, A> operator+(
const basic_string<E, T, A>& lhs,
const E *rhs);
template<class E, class T, class A>
basic_string<E, T, A> operator+(
const basic_string<E, T, A>& lhs,
E rhs);
template<class E, class T, class A>
basic_string<E, T, A> operator+(
const E *lhs,
const basic_string<E, T, A>& rhs);
template<class E, class T, class A>
basic_string<E, T, A> operator+(
E lhs,
const basic_string<E, T, A>& rhs);
template<class E, class T, class A>
bool operator==(
const basic_string<E, T, A>& lhs,
const basic_string<E, T, A>& rhs);
template<class E, class T, class A>
bool operator==(
const basic_string<E, T, A>& lhs,
const E *rhs);
template<class E, class T, class A>
bool operator==(
const E *lhs,
const basic_string<E, T, A>& rhs);
template<class E, class T, class A>
bool operator!=(
const basic_string<E, T, A>& lhs,
const basic_string<E, T, A>& rhs);
template<class E, class T, class A>
bool operator!=(
const basic_string<E, T, A>& lhs,
const E *rhs);
template<class E, class T, class A>
bool operator!=(
const E *lhs,
const basic_string<E, T, A>& rhs);
template<class E, class T, class A>
bool operator<(
const basic_string<E, T, A>& lhs,
const basic_string<E, T, A>& rhs);
basic_string
template<class E,
class T = char_traits<E>,
class A = allocator<T> >
class basic_string {
public:
typedef T traits_type;
typedef A allocator_type;
typedef T::char_type char_type;
typedef A::size_type size_type;
typedef A::difference_type difference_type;
typedef A::pointer pointer;
typedef A::const_pointer const_pointer;
typedef A::reference reference;
typedef A::const_reference const_reference;
typedef A::value_type value_type;
typedef T0 iterator;
typedef T1 const_iterator;
typedef reverse_iterator<iterator, value_type,
reference, pointer, difference_type>
reverse_iterator;
typedef reverse_iterator<const_iterator, value_type,
const_reference, const_pointer, difference_type>
const_reverse_iterator;
static const size_type npos = -1;
explicit basic_string(const A& al = A());
basic_string(const basic_string& rhs);
basic_string(const basic_string& rhs, size_type pos, size_type n
const A& al = A());
basic_string(const E *s, size_type n, const A& al = A());
basic_string(const E *s, const A& al = A());
basic_string(size_type n, E c, const A& al = A());
basic_string(const_iterator first, const_iterator last,
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. (Class char_traits has no provision
for alternative addressing schemes, such as might be required to
implement a far heap.) Note that allocator is not copied when the
object is assigned.
basic_string::allocator_type
typedef A allocator_type;
basic_string::append
template<class InIt>
basic_string& append(InIt first, InIt last);
is replaced by:
basic_string::assign
template<class InIt>
basic_string& assign(InIt first, InIt last);
is replaced by:
basic_string::at
basic_string::basic_string
Each constructor stores the allocator object al (or, for the copy
constructor, x.get_allocator()) in allocator and initializes the
controlled sequence to a copy of the operand sequence specified by
the remaining operands. The explicit constructor specifies an empty
initial controlled sequence.
is replaced by:
basic_string::begin
empty sequence).
basic_string::c_str
basic_string::capacity
basic_string::char_type
basic_string::compare
basic_string::const_iterator
typedef T1 const_iterator;
basic_string::const_pointer
basic_string::const_reference
basic_string::const_reverse_iterator
basic_string::copy
basic_string::data
basic_string::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
basic_string::empty
basic_string::end
basic_string::erase
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
basic_string::get_allocator
A get_allocator() const;
basic_string::insert
template<class InIt>
void insert(iterator it, InIt first, InIt last);
is replaced by:
basic_string::iterator
typedef T0 iterator;
basic_string::length
basic_string::max_size
The member function returns the length of the longest sequence that
the object can control.
basic_string::npos
basic_string::operator+=
basic_string::operator=
basic_string::operator[]
basic_string::pointer
basic_string::rbegin
basic_string::reference
basic_string::rend
basic_string::replace
template<class InIt>
basic_string& replace(iterator first0, iterator last0,
InIt first, InIt last);
is replaced by:
basic_string::reserve
basic_string::resize
basic_string::reverse_iterator
basic_string::rfind
basic_string::size
basic_string::size_type
basic_string::substr
basic_string::swap
basic_string::traits_type
typedef T traits_type;
basic_string::value_type
char_traits
struct char_traits<E> {
typedef E char_type;
typedef T1 int_type;
typedef T2 pos_type;
typedef T3 off_type;
typedef T4 state_type;
static void assign(E& x, const E& y);
static E *assign(E *x, size_t n, const E& y);
static bool eq(const E& x, const E& y);
static bool lt(const E& x, const E& y);
static int compare(const E *x, const E *y, size_t n);
static size_t length(const E *x);
static E *copy(E *x, const E *y, size_t n);
static E *move(E *x, const E *y, size_t n);
static const E *find(const E *x, size_t n, const E& y);
static E to_char_type(const int_type& ch);
static int_type to_int_type(const E& c);
static bool eq_int_type(const int_type& ch1, const int_type& ch2
static int_type eof();
static int_type not_eof(const int_type& ch);
};
char_traits::assign
char_traits::char_type
typedef E char_type;
char_traits::compare
char_traits::copy
char_traits::eof
char_traits::eq
char_traits::eq_int_type
char_traits::find
The static member function determines the lowest N in the range [0,
n) for which eq(x[N], y) is true. If successful, it returns x + N.
Otherwise, it returns a null pointer.
char_traits::int_type
typedef T1 int_type;
char_traits::length
char_traits::lt
char_traits::move
char_traits::not_eof
char_traits::off_type
typedef T3 off_type;
char_traits::pos_type
typedef T2 pos_type;
char_traits::state_type
typedef T4 state_type;
char_traits::to_char_type
char_traits::to_int_type
char_traits<char>
class char_traits<char>;
char_traits<wchar_t>
class char_traits<wchar_t>;
getline
operator+
operator!=
operator==
operator<
operator<<
operator<=
operator>
operator>=
operator>>
string
swap
wstring
<strstream>
namespace std {
class strstreambuf;
class istrstream;
class ostrstream;
class strstream;
};
strstreambuf
strstreambuf::freeze
strstreambuf::pcount
streamsize pcount();
strstreambuf::strstreambuf
also behave much as the first, except that gp designates the array
object used to hold the controlled sequence. (Therefore, it must
not be a null pointer.) The number of elements N in the array is
determined as follows:
except that the stored mode makes the controlled sequence neither
modifiable nor extendable.
strstreambuf::overflow
buffer. (Extending the output buffer this way also extends any
associated input buffer.)
strstreambuf::pbackfail
strstreambuf::seekoff
If which & ios_base::in is nonzero and the input buffer exists, the
function alters the next position to read in the input buffer. If
which & ios_base::out is also nonzero, way != ios_base::cur, and
the output buffer exists, the function also sets the next position
to write to match the next position to read.
strstreambuf::seekpos
If which & ios_base::in is nonzero and the input buffer exists, the
function alters the next position to read in the input buffer. (If
which & ios_base::out is nonzero and the output buffer exists, the
function also sets the next position to write to match the next
position to read.) Otherwise, if which & ios_base::out is nonzero
and the output buffer exists, the function alters the next position
to write in the output buffer. Otherwise, the positioning operation
fails. For a positioning operation to succeed, the resulting stream
position must lie within the controlled sequence.
strstreambuf::str
char *str();
strstreambuf::underflow
istrstream
istrstream::istrstream
istrstream::rdbuf
istrstream::str
char *str();
ostrstream
ostrstream::freeze
ostrstream::ostrstream
ostrstream();
ostrstream(char *s, streamsize n,
ios_base::openmode mode = ios_base::out);
ostrstream::pcount
ostrstream::rdbuf
ostrstream::str
char *str();
strstream
strstream::freeze
strstream::pcount
strstream::strstream
strstream();
strstream(char *s, streamsize n,
ios_base::openmode mode = ios_base::in | ios_base::out);
strstream::rdbuf
strstream::str
char *str();
<utility>
namespace std {
// TEMPLATE CLASSES
template<class T, class U>
struct pair;
// TEMPLATE FUNCTIONS
template<class T, class U>
pair<T, U> make_pair(const T& x, const U& y);
template<class T, class U>
bool operator==(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator!=(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator<(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator>(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator<=(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator>=(const pair<T, U>& x, const pair<T, U>& y);
namespace rel_ops {
template<class T>
bool operator!=(const T& x, const T& y);
template<class T>
bool operator<=(const T& x, const T& y);
template<class T>
bool operator>(const T& x, const T& y);
template<class T>
bool operator>=(const T& x, const T& y);
};
};
make_pair
operator!=
template<class T>
bool operator!=(const T& x, const T& y);
operator==
operator<
operator<=
template<class T>
bool operator<=(const T& x, const T& y);
template<class T, class U>
bool operator<=(const pair<T, U>& x, const pair<T, U>& y);
operator>
template<class T>
bool operator>(const T& x, const T& y);
template<class T, class U>
bool operator>(const pair<T, U>& x, const pair<T, U>& y);
operator>=
template<class T>
bool operator>=(const T& x, const T& y);
template<class T, class U>
bool operator>=(const pair<T, U>& x, const pair<T, U>& y);
pair
<valarray>
gslice . gslice_array .
indirect_array . mask_array . slice .
slice_array . valarray . valarray<bool>
abs . acos . asin . atan . atan2 . cos . cosh . exp . log . log10 .
max . min . operator!= . operator% . operator& . operator&& .
operator> . operator>> . operator>= . operator< . operator<< .
operator<= .
operator* . operator+ . operator- . operator/ .
operator== . operator^ . operator| . operator|| . pow . sin . sinh
. sqrt . tan . tanh
namespace std {
class slice;
class gslice;
// TEMPLATE CLASSES
template<class T>
class valarray;
template<class T>
class slice_array;
template<class T>
class gslice_array;
template<class T>
class mask_array;
template<class T>
class indirect_array;
// TEMPLATE FUNCTIONS
template<class T>
valarray<T> operator*(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator*(const valarray<T> lhs,
const T& rhs);
template<class T>
valarray<T> operator*(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator/(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator/(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator/(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator%(const valarray<T>& lhs,
const vararray<T>& rhs);
template<class T>
valarray<T> operator%(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator%(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator+(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator+(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator+(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator-(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator-(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator-(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator^(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator^(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator^(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator&(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator&(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator&(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator|(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator|(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator|(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator<<(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator<<(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator<<(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<T> operator>>(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator>>(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator>>(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator&&(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator&&(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator&&(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<biil> operator||(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator||(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator||(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator==(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator==(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator==(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator!=(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator!=(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator!=(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator<(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator<(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator<(const T& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator>=(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator>=(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator>=(const T& lhs, const valarray<T>& rhs);
template<class T>
template<class T>
valarray<T> tanh(const valarray<T>& x);
};
abs
template<class T>
valarray<T> abs(const valarray<T>& x);
acos
template<class T>
valarray<T> acos(const valarray<T>& x);
asin
template<class T>
valarray<T> asin(const valarray<T>& x);
atan
template<class T>
valarray<T> atan(const valarray<T>& x);
atan2
template<class T>
valarray<T> atan2(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<T> atan2(const valarray<T> x, const T& y);
template<class T>
valarray<T> atan2(const T& x, const valarray<T>& y);
cos
template<class T>
valarray<T> cos(const valarray<T>& x);
cosh
template<class T>
valarray<T> cosh(const valarray<T>& x);
exp
template<class T>
valarray<T> exp(const valarray<T>& x);
gslice
class gslice {
public:
gslice();
gslice(size_t st,
const valarray<size_t> len, const valarray<size_t> str);
size_t start() const;
const valarray<size_t> size() const;
const valarray<size_t> stride() const;
};
lA starting index
lA length vector of class valarray<size_t>
lA stride vector of class valarray<size_t>
gslice::gslice
gslice();
gslice(size_t st,
const valarray<size_t> len, const valarray<size_t> str);
The default constructor stores zero for the starting index, and
zero-length vectors for the length and stride vectors. The second
constructor stores st for the starting index, len for the length
vector, and str for the stride vector.
gslice::size
gslice::start
gslice::stride
gslice_array
template<class T>
class gslice_array {
public:
typedef T value_type;
void operator=(const valarray<T> x) const;
void operator=(const T& x);
void operator*=(const valarray<T> x) const;
void operator/=(const valarray<T> x) const;
void operator%=(const valarray<T> x) const;
void operator+=(const valarray<T> x) const;
void operator-=(const valarray<T> x) const;
void operator^=(const valarray<T> x) const;
void operator&=(const valarray<T> x) const;
void operator|=(const valarray<T> x) const;
void operator<<=(const valarray<T> x) const;
k = start;
for (size_t i = 0; i < gs.size()[i]; ++i)
k += idx[i] * gs.stride()[i];
For example:
indirect_array
template<class T>
class indirect_array {
public:
typedef T value_type;
void operator=(const valarray<T> x) const;
void operator=(const T& x);
void operator*=(const valarray<T> x) const;
void operator/=(const valarray<T> x) const;
void operator%=(const valarray<T> x) const;
void operator+=(const valarray<T> x) const;
void operator-=(const valarray<T> x) const;
void operator^=(const valarray<T> x) const;
void operator&=(const valarray<T> x) const;
void operator|=(const valarray<T> x) const;
void operator<<=(const valarray<T> x) const;
log
template<class T>
valarray<T> log(const valarray<T>& x);
log10
template<class T>
valarray<T> log10(const valarray<T>& x);
mask_array
template<class T>
class mask_array {
public:
typedef T value_type;
void operator=(const valarray<T> x) const;
void operator=(const T& x);
void operator*=(const valarray<T> x) const;
void operator/=(const valarray<T> x) const;
void operator%=(const valarray<T> x) const;
void operator+=(const valarray<T> x) const;
void operator-=(const valarray<T> x) const;
void operator^=(const valarray<T> x) const;
void operator&=(const valarray<T> x) const;
max
template<class T>
T max(const valarray<T>& x);
Microsoft-Specific:
To avoid conflicts with min and max in WINDEF.H, use _MIN and _MAX
instead. These macros evaluate to _cpp_min and _cpp_max,
respectively.
END Microsoft-Specific
min
template<class T>
T min(const valarray<T>& x);
Microsoft-Specific:
To avoid conflicts with min and max in WINDEF.H, use _MIN and _MAX
instead. These macros evaluate to _cpp_min and _cpp_max,
respectively.
END Microsoft-Specific
operator!=
template<class T>
valarray<bool> operator!=(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<bool> operator!=(const valarray<T> x, const T& y);
template<class T>
valarray<bool> operator!=(const T& x, const valarray<T>& y);
operator%
template<class T>
valarray<T> operator%(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator%(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator%(const T& lhs, const valarray<T>& rhs);
operator&
template<class T>
valarray<T> operator&(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator&(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator&(const T& lhs, const valarray<T>& rhs);
operator&&
template<class T>
valarray<bool> operator&&(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator&&(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator&&(const T& lhs, const valarray<T>& rhs);
operator>
template<class T>
valarray<bool> operator>(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<bool> operator>(const valarray<T> x, const T& y);
template<class T>
valarray<bool> operator>(const T& x, const valarray<T>& y);
operator>>
template<class T>
valarray<T> operator>>(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator>>(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator>>(const T& lhs, const valarray<T>& rhs);
operator>=
template<class T>
valarray<bool> operator>=(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<bool> operator>=(const valarray<T> x, const T& y);
template<class T>
valarray<bool> operator>=(const T& x, const valarray<T>& y);
operator<
template<class T>
valarray<bool> operator<(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<bool> operator<(const valarray<T> x, const T& y);
template<class T>
valarray<bool> operator<(const T& x, const valarray<T>& y);
operator<<
template<class T>
valarray<T> operator<<(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator<<(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator<<(const T& lhs, const valarray<T>& rhs);
operator<=
template<class T>
valarray<bool> operator<=(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<bool> operator<=(const valarray<T> x, const T& y);
template<class T>
valarray<bool> operator<=(const T& x, const valarray<T>& y);
operator*
template<class T>
valarray<T> operator*(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator*(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator*(const T& lhs, const valarray<T>& rhs);
operator+
template<class T>
valarray<T> operator+(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
operator-
template<class T>
valarray<T> operator-(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator-(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator-(const T& lhs, const valarray<T>& rhs);
operator/
template<class T>
valarray<T> operator/(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator/(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator/(const T& lhs, const valarray<T>& rhs);
operator==
template<class T>
valarray<bool> operator==(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<bool> operator==(const valarray<T> x, const T& y);
template<class T>
valarray<bool> operator==(const T& x const valarray<T>& y);
operator^
template<class T>
operator|
template<class T>
valarray<T> operator|(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<T> operator|(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<T> operator|(const T& lhs, const valarray<T>& rhs);
operator||
template<class T>
valarray<bool> operator||(const valarray<T>& lhs,
const valarray<T>& rhs);
template<class T>
valarray<bool> operator||(const valarray<T> lhs, const T& rhs);
template<class T>
valarray<bool> operator||(const T& lhs, const valarray<T>& rhs);
pow
template<class T>
valarray<T> pow(const valarray<T>& x,
const valarray<T>& y);
template<class T>
valarray<T> pow(const valarray<T> x, const T& y);
template<class T>
valarray<T> pow(const T& x, const valarray<T>& y);
sin
template<class T>
valarray<T> sin(const valarray<T>& x);
sinh
template<class T>
valarray<T> sinh(const valarray<T>& x);
slice
class slice {
public:
slice();
slice(size_t st, size_t len, size_t str);
size_t start() const;
size_t size() const;
size_t stride() const;
};
lA starting index
lA total length
lA stride, or distance between subsequent indices
slice::size
slice::start
slice::slice
slice();
slice(size_t st,
const valarray<size_t> len, const valarray<size_t> str);
The default constructor stores zeros for the starting index, total
length, and stride. The second constructor stores st for the
starting index, len for the total length, and str for the stride.
slice::stride
slice_array
template<class T>
class slice_array {
public:
typedef T value_type;
void operator=(const valarray<T> x) const;
void operator=(const T& x);
void operator*=(const valarray<T> x) const;
void operator/=(const valarray<T> x) const;
void operator%=(const valarray<T> x) const;
void operator+=(const valarray<T> x) const;
void operator-=(const valarray<T> x) const;
void operator^=(const valarray<T> x) const;
void operator&=(const valarray<T> x) const;
void operator|=(const valarray<T> x) const;
void operator<<=(const valarray<T> x) const;
void operator>>=(const valarray<T> x) const;
void fill();
};
sqrt
template<class T>
valarray<T> sqrt(const valarray<T>& x);
tan
template<class T>
valarray<T> tan(const valarray<T>& x);
tanh
template<class T>
valarray<T> tanh(const valarray<T>& x);
valarray
template<class T>
class valarray {
public:
typedef T value_type;
valarray();
explicit valarray(size_t n);
valarray(const T& val, size_t n));
valarray(const T *p, size_t n);
valarray(const slice_array<T>& sa);
valarray(const gslice_array<T>& ga);
valarray(const mask_array<T>& ma);
valarray(const indirect_array<T>& ia);
valarray<T>& operator=(const valarray<T>& va);
valarray<T>& operator=(const T& x);
valarray<T>& operator=(const slice_array<T>& sa);
valarray<T>& operator=(const gslice_array<T>& ga);
valarray<T>& operator=(const mask_array<T>& ma);
valarray<T>& operator=(const indirect_array<T>& ia);
T operator[](size_t n) const;
T& operator[](size_t n);
valarray<T> operator[](slice sa) const;
slice_array<T> operator[](slice sa);
valarray<T> operator[](const gslice& ga) const;
valarray::apply
valarray::cshift
valarray::fill
valarray::free
void free();
valarray::max
T max() const;
valarray::min
T min() const;
valarray::operator!
valarray<bool> operator!();
valarray::operator%=
valarray::operator&=
valarray::operator>>=
valarray::operator<<=
valarray::operator*=
valarray::operator+
valarray<T> operator+();
valarray::operator+=
valarray::operator-
valarray<T> operator-();
valarray::operator-=
valarray::operator/=
valarray::operator=
valarray::operator[]
T operator[](size_t n) const;
valarray<T> operator[](slice sa) const;
valarray<T> operator[](const gslice& ga) const;
valarray<T> operator[](const valarray<bool>& ba) const;
valarray<T> operator[](const valarray<size_t>& xa) const;
valarray::operator^=
valarray::operator|=
valarray::operator~
valarray<T> operator~();
valarray::resize
valarray::shift
valarray::size
valarray::sum
T sum() const;
The member function returns the sum of all elements of *this, which
must have nonzero length. If the length is greater than one, it
adds values to the sum by applying operator+= between pairs of
elements of class T.
valarray::valarray
valarray();
explicit valarray(size_t n);
valarray(const T& val, size_t n));
valarray(const T *p, size_t n);
valarray(const slice_array<T>& sa);
valarray(const gslice_array<T>& ga);
valarray(const mask_array<T>& ma);
valarray(const indirect_array<T>& ia);
valarray::value_type
typedef T value_type;
valarray<bool>
class valarray<bool>
<vector>
namespace std {
template<class T, class A>
class vector;
template<class A>
class vector<bool, A>;
// TEMPLATE FUNCTIONS
template<class T, class A>
bool operator==(
const vector<T, A>& lhs,
const vector<T, A>& rhs);
template<class T, class A>
bool operator!=(
const vector<T, A>& lhs,
const vector<T, A>& rhs);
template<class T, class A>
bool operator<(
const vector<T, A>& lhs,
const vector<T, A>& rhs);
template<class T, class A>
bool operator>(
const vector<T, A>& lhs,
const vector<T, A>& rhs);
template<class T, class A>
bool operator<=(
const vector<T, A>& lhs,
const vector<T, A>& rhs);
template<class T, class A>
bool operator>=(
const vector<T, A>& lhs,
const vector<T, A>& rhs);
template<class T, class A>
void swap(
const vector<T, A>& lhs,
const vector<T, A>& rhs);
};
operator!=
operator==
operator<
operator<=
operator>
operator>=
swap
vector
The object allocates and frees storage for the sequence it controls
through a protected object named allocator, of class A. Such an
allocator object must have the same external interface as an object
of template class allocator. Note that allocator is not copied when
the object is assigned.
vector::allocator_type
typedef A allocator_type;
vector::assign
template<class InIt>
vector::at
vector::back
reference back();
const_reference back() const;
vector::begin
vector::capacity
vector::clear
vector::const_iterator
typedef T1 const_iterator;
vector::const_reference
vector::const_reverse_iterator
vector::difference_type
The signed integer type describes an object that can represent the
difference between the addresses of any two elements in the
controlled sequence.
vector::empty
vector::end
vector::erase
become invalid only from the first element erased through the end
of the sequence.
vector::front
reference front();
const_reference front() const;
vector::get_allocator
A get_allocator() const;
vector::insert
template<class InIt>
void insert(iterator it, InIt first, InIt last);
is replaced by:
vector::iterator
typedef T0 iterator;
vector::max_size
The member function returns the length of the longest sequence that
the object can control.
vector::operator[]
vector::pop_back
void pop_back();
vector::push_back
vector::rbegin
vector::reference
vector::rend
vector::reserve
vector::resize
vector::reverse_iterator
vector::size
vector::size_type
vector::swap
vector::value_type
vector::vector
All constructors store the allocator object al (or, for the copy
constructor, x.get_allocator()) in allocator and initialize the
controlled sequence. The first constructor specifies an empty
initial controlled sequence. The second constructor specifies a
repetition of n elements of value x. The third constructor
specifies a copy of the sequence controlled by x. The last
constructor specifies the sequence [first, last).
template<class InIt>
vector(InIt first, InIt last, const A& al = A());
is replaced by:
vector<bool, A>
vector<bool, A>::const_iterator
typedef T1 const_iterator;
vector<bool, A>::const_reference
vector<bool, A>::flip
void flip();
The member function inverts the values of all the members of the
controlled sequence.
vector<bool, A>::iterator
typedef T0 iterator;
vector<bool, A>::reference
class reference {
public:
reference& operator=(const reference& x);
reference& operator=(bool x);
void flip();
bool operator~() const;
operator bool() const;
};
vector<bool, A>::swap
and
and_eq
bitand
bitor
compl
not
not_eq
or
or_eq
xor
xor_eq
Include the standard header <wchar.h> so that you can perform input
and output operations on wide streams or manipulate wide strings.
WCHAR_MAX
WCHAR_MIN
btowc
fwide
mbrlen
mbrtowc(0, s, n, ps != 0 ? ps : &internal)
mbrtowc
mbsinit
mbsrtowcs
mbstate_t
typedef o-type
wcrtomb
wcsrtombs
wctob
wmemchr
wmemcmp
wmemcpy
wmemmove
wmemset
labs
laccumulate, copy, vector::push_back
ladjacent_difference, vector::push_back
ladvance
lBasic Math Functions
lbasic_string::append
lbasic_string size and resize
lbinary_function Structure
lcount
lcount_if
ldeque::assign and deque::swap
ldeque::begin and deque::end
ldeque::erase and deque::clear
ldeque::front and deque::back
ldeque::insert
ldeque::operator[] and deque::at
ldeque::push_back and deque::pop_back
ldeque::push_front, deque::pop_front
ldeque::rbegin and deque::rend
ldeque::size and deque::resize
ldistance
lexp, log, and log10
lfind
lfind_if
lfor_each
lgenerate
lgenerate_n
lheap
lheap (predicate version)
lincludes
lincludes (predicate version)
linner_product
linplace_merge
linplace_merge (predicate version)
liter_swap
llist::assign
llist::back, list::front
ldeque::insert
llist::list
llower_bound
llower_bound (predicate version)
lmake_pair
lmap::insert, map::find, and map::end
lmax_element
lmax_element (predicate version)
lmap::max_size, clear, erase, size
lmerge
lmerge (predicate version)
lmin_element
lmin_element (predicate version)
lnew operator
lnext_permutation
lnext_permutation (predicate version)
lnth_element
lnth_element (predicate version)
lMembers of the numeric_limits Class
loperator == and operator < deque
lPair Logical Operator
lpartial_sort
lpartial_sort_copy
lpartial_sort_copy (predicate version)
lpartial_sort (predicate version)
lpartial_sum
lpartition
lprev_permutation
lpriority_queue functions
lqueue functions
lrandom_shuffle
lrandom_shuffle
lremove
lremove_copy
lremove_copy_if
lremove_if
lreplace
lreplace_copy
lreplace_copy_if
lreplace_if
lreverse
lreverse_copy
lrotate
lrotate_copy
lset::(lower_, upper_)bound, equal_range
lset::(key_, value_)comp
lset::count
lset::empty and set::clear
lset::find
lset::max_size
lset::rbegin and set::rend
lset::size
lset::swap, begin, end
lsqrt and pow
lstack::operator==
lstack::operator<
lstack::size
lstack::top and stack::empty
lstring::getline
lstring::operator==
lstring::operator>
lstring::operator>=
lstring::operator>>
lstring::operator<
lstring::operator<=
lstring::operator<<
lstring::operator+
lstring::operator!=
lTrigonometry Functions
lunary_function<> Structure
lupper_bound
lupper_bound (predicate version)
lVector Class, operator==
lvector::empty, erase, and push_back
lvector::front and vector::back
lVector Class, operator<
lvector::push_back and vector::pop_back
lvector::size and vector::capacity
The sample code below illustrates how to use the abs STL function
in Visual C++.
Required Header:
<valarray>
Prototype:
template<class T>
Description:
The sample declares a valarray of integers and uses the abs()STL
function to get the absolute value for each array element.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: None
//
// <filename> : main.cpp
//
// Functions:
//
// abs
//
////////////////////////////////////////////////////////////////////
void main()
{
// Initialize val_array to 0, -1, -2, etc.
INTVALARRAY val_array(ARRAY_SIZE);
for (int i = 0; i < ARRAY_SIZE; i++)
val_array[i] = -i;
Size of val_array = 10
The sample code below illustrates how to use the accumulate, copy,
and vector::push_back STL functions in Visual C++.
Required Header:
<numeric>
Prototype:
Description:
The accumulate function initializes an accumulator acc with an
initial value init and then modifies it with acc = acc + *i or acc
= binary_op(acc,*i) for every iterator i in the range [first, last)
in order. Normally, the accumulate function is used to sum the
numeric elements of a vector. However, it can also be used to do
other useful work such as concatenating a vector of strings.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// accumulate.cpp : Demonstrates the use of accumulate()
//
// Description of accumulate(first,last,init)
// accumulate(first,last,init,binary_op):
//
// Initializes the accumulator acc with the initial value init
// acc = init
// and then modifies it with
// acc = acc + *i
// or
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
#include <string>
void main ()
{
// a vector of floats
FloatArray rgFA;
<< endl;
}
Required Header:
<numeric>
Prototype:
Description:
Assigns to every element referred to by iterator i in the range
[result + 1, result + (last - first)) a value correspondingly equal
to *(first + (i - result)) - *(first + (i - result) - 1) or
binary_op (*(first + (i - result)), *(first + (i - result) - 1)).
Result gets the value of *first.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// adj_diff.cpp : Demonstrates the use of adjacent_difference()
//
// Description of adjacent_difference(first,last,result)
// adjacent_difference(first,last,result,binary_op):
//
// Assigns to every element referred to by iterator i in the rang
// [result + 1, result + (last - first))
// a value correspondingly equal to
// *(first + (i - result)) - *(first + (i - result) - 1)
// or
// binary_op(*(first + (i - result)), *(first + (i - result) - 1)
// Result gets the value of *first.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
void main ()
{
// an ostream iterator that outputs an int to cout terminated
// by a space
IntOstreamIt itOstream(cout," ");
Required Header:
<algorithm>
Prototype:
Description:
The adjacent_find algorithm finds consecutive pairs of matching
elements in a sequence. The adjacent_find algorithm returns an
iterator referencing the first consecutive matching element in the
range (first, last), or last if there are no such elements.
Comparison is done using operator== in this non-predicate version
of the algorithm.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// adfind.cpp : Illustrates how to use the non-predicate version of
// adjacent_find function.
//
// Functions:
//
// adjacent_find - Locate a matching consecutive sequence in a ran
////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <iostream>
void main()
{
const int ARRAY_SIZE = 8 ;
int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } ;
int i ;
IntArray { 1, 2, 3, 4, 4, 5, 6, 7, }
Found adjacent pair of matching elements: (4, 4), at location 3
The sample code below illustrates how to use the predicate version
of the adjacent_find STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The adjacent_find algorithm finds consecutive pairs of matching
elements in a sequence. adjacent_find returns an iterator
referencing the first consecutive matching element in the range
[first, last), or last if there are no such elements. Comparison is
done using the binary_pred function in this version of the
algorithm. The binary_pred function can be any user-defined
function. You could also use one of the binary function objects
provided by STL.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// adfind.cpp : Illustrates how to use the predicate version of
// adjacent_find function.
//
// Functions:
//
// adjacent_find - Locate a consecutive sequence in a range.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
void main()
{
const int VECTOR_SIZE = 5 ;
// print the first pair of strings such that the first name is
// lexicographically greater than the second.
if (location != end)
cout << "(" << *location << ", " << *(location + 1) << ")"
<< " the first pair of strings in NamesVect such that\n"
<< "the first name is lexicographically greater than"
<< "the second\n" << endl ;
else
cout << "No consecutive pair of strings found such that\n"
<< "the first name is lexicographically greater than "
<< "the second\n" << endl ;
The sample code below illustrates how to use the advance STL
function in Visual C++.
Required Header:
<iterator>
Prototype:
Description:
The advance function accepts two parameters:
- InIt: The iterator to advance.
- Dist: The number of elements to increment the iterator by.
The advance function advances the iterator n times. If the iterator
is a random-access iterator type, the function evaluates the
expression as iterator += n. Otherwise, it performs each increment
by evaluating: ++iterator. If the iterator is an input or forward
iterator type, n must not be negative. NOTE: The class/parameter
names in the prototype may not match the version in the header
file. Some have been modified to improve readability.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : Advance.cpp
//
// Functions:
//
// advance()
////////////////////////////////////////////////////////////////////
#include <string>
#include <list>
#pragma warning (disable:4786)
void main() {
STRLIST List;
STRLIST::iterator iList;
STRLIST::difference_type dTheDiff;
List.push_back("A1");
List.push_back("B2");
List.push_back("C3");
List.push_back("D4");
List.push_back("E5");
List.push_back("F6");
List.push_back("G7");
The element is C3
The sample code below illustrates how to use some basic math
functions in Visual C++.
Required Header:
< functional >
Prototype:
template<class _TYPE>
Description:
This sample uses a class derived from all five basic math
structures: plus, minus, times, divides, and modulus, using an
integer as the templated operand.
Sample Code:
////////////////////////////////////////////////////////////////
//
// Compile options needed: none
//
// mathfunc.cpp - Illustrating the basic STL math
// functions.
//
// Structures: plus<A> - Adds data type A object to
// a class object derived from plus.
// minus<A> - Subtracts data type A.
// multiplies<A> - Multiplies object by data type A.
// divides<A> - Divides object by data type A.
// modulus<A> - Returns object modulo A.
/////////////////////////////////////////////////////////////////
#include <functional>
#include <iostream>
void main(void)
{
MathOps one,two,three,four,five,six;
one = 18;
cout << "one = " << one << endl ;
two = one + 1;
cout << "two = one + 1 = " << two << endl ;
three = two - 2;
cout << "three = two - 2 = " << three << endl ;
four = three * 3;
cout << "four = three * 3 = " << four << endl ;
five = four / 4;
cout << "five = four / 4 = " << five << endl ;
six = five % 5;
cout << "six = five % 5 = " << six << endl ;
}
Required Header:
<string>
Prototype:
Description:
The append member functions of the basic_string append elements to
the end of the string. The different forms of the function provide
alternate ways to specify the source of the elements that will be
appended. The append functions return a reference to the string to
which the elements were appended.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// bsappend.cpp : Illustrates how to use the string append member
// function.
//
// Functions:
//
// string::append - appends a sequence of elements to the
// current string.
////////////////////////////////////////////////////////////////////
#include <string>
#include <iostream>
void main()
{
string str1("012");
string str2("345");
str1 = 012
str1 = 012345
str1 = 01234567
str1 = 0123456789
str1 = 0123456789ABC
str1 = 0123456789ABCD
str1 = 0123456789ABCDEF
Required Header:
<string>
Prototype:
Description:
The member functions each find the first (lowest position) element
of the controlled sequence at or after position iPos that matches
any of the elements in the operand sequence specified by the
remaining operands. If it succeeds, it returns the position.
Otherwise, the function returns npos. The position returned is 0
(zero) based. The npos return value is a special value indicating
that none of the elements were found.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// main.cpp : Demonstrates the use of the string::find_first_of().
//
// Functions:
//
// string::find_first_of() - find the first instance in the
// controlled string of any of the elements specified by the
// parameters. The search begins at an optionally-supplied
// position in the controlled string.
////////////////////////////////////////////////////////////////////
#include <string>
#include <iostream>
void main()
{
string str1("Heartbeat");
string str2("abcde");
int iPos = 0;
cout << "The string to search is '" << str1.c_str() << "'"
<< endl;
cout << "Element in '" << str2.c_str() << "' found at position "
<< iPos << endl;
cout << "Element in '" << str2.c_str() << "' found at position "
<< iPos << endl;
cout << "Element in '" << szVowels << "' found at position "
<< iPos << endl;
cout << "'e' found at position " << iPos << endl;
}
The sample code below illustrates how to use the basic_string size
and resize STL functions in Visual C++.
Required Header:
<string>
Prototype:
Description:
The size function returns the length of the sequence. The resize
function changes the size to the length specified by the first
parameter. If the sequence is made longer, the function appends
elements with the value of the second parameter. This value
defaults to a null. The output of the sample code shows spaces for
the null characters. operator<< reads the size of string and
outputs each character in the string one at a time.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : size.cpp
//
// Functions:
//
// size()
// resize() ; Defined in header xstring which is included indirec
////////////////////////////////////////////////////////////////////
void main()
{
string TestString = "1111122222333334444455555";
cout << TestString << "\n size: " << TestString.size() << endl;
TestString.resize(5);
cout << TestString << "\n size: " << TestString.size() << endl;
TestString.resize(10);
cout << TestString << "\n size: " << TestString.size() << endl;
TestString.resize(15,'6');
cout << TestString << "\n size: " << TestString.size() << endl;
}
1111122222333334444455555
size: 25
11111
size: 5
11111
size: 10
11111 66666
size: 15
Required Header:
< functional >
Prototype:
Description:
The binary_function<A,B,C> class is used as a base class to allow
the user to easily define binary operator functions that take data
types A and B as arguments and return data type C objects.
Sample Code:
////////////////////////////////////////////
//
// Compile options needed: /GX
//
// binfunc.cpp : Illustrating the binary_function
// structure.
//
// Structure used: binary_function<A,B,C> - base
// class used to create operator
// functions taking data types A
// and B and returning data type C.
////////////////////////////////////////////
#include <functional>
#include <iostream>
binary_test::result_type
binary_test::operator<<(binary_test::second_argument_type arg2)
{
value = ((int)value) << arg2;
cout << "New value after shift is" << value << endl;
return value;
}
void main(void)
{
binary_test item;
Begin
New value after shift is 40.0
The sample code below illustrates how to use the count STL function
in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// count.cpp : Illustrates how to use the count function.
//
// Functions:
//
// count - Count items in a range that match a value.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
NamesVect[6] = "Sea" ;
NamesVect[7] = "Shore" ;
The sample code below illustrates how to use the count_if STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The count_if algorithm counts the number of elements in the range
[first, last) that cause the predicate to return true, and returns
the number of elements for which the predicate was true.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// count.cpp : Illustrates how to use the count_if function.
//
// Functions:
//
// count_if - Count items in a range that satisfy a predicate.
//
// begin - Returns an iterator that points to the first elemen
// a sequence.
//
// end - Returns an iterator that points one past the end of
// sequence.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
NamesVect[1] = "Sells" ;
NamesVect[2] = "Sea" ;
NamesVect[3] = "Shells" ;
NamesVect[4] = "by" ;
NamesVect[5] = "the" ;
NamesVect[6] = "Sea" ;
NamesVect[7] = "Shore" ;
The sample code below illustrates how to use the deque::assign and
deque::swap STL functions in Visual C++.
Required Header:
< deque>
Prototype:
Description:
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// assign
// swap
// begin
// end
////////////////////////////////////////////////////////////////////
void main()
{
//create a with 3 A's
CHARDEQUE a(3,'A');
//swap a and b
a.swap(b);
print_contents (a,"a");
print_contents (b,"b");
print_contents (a,"a");
//assign 3 'Z's to a
a.assign(3,'Z');
print_contents (a,"a");
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
The contents of a : A A A
The contents of b : B B B B
The contents of a : B B B B
The contents of b : A A A
The contents of a : A A A
The contents of b : B B B B
The contents of a : B B B B
The contents of a : B B
The contents of a : Z Z Z
The sample code below illustrates how to use the deque::begin and
deque::end STL functions in Visual C++.
Required Header:
< deque>
Prototype:
iterator end();
Description:
The begin member function returns a random-access iterator that
points at the first element of the sequence, or just beyond the end
of an empty sequence. The end member function returns a random-
access iterator that points just beyond the end of the sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// begin()
// end()
////////////////////////////////////////////////////////////////////
void main()
{
INTDEQUE A;
A.push_back(1);
A.push_back(2);
A.push_back(3);
A.push_back(4);
A.push_back(5);
INTDEQUE::iterator pi;
}
cout<<endl;
}
1 2 3 4 5
The sample code below illustrates how to use the deque::erase and
deque::clear STL functions in Visual C++.
Required Header:
< deque>
Prototype:
Description:
The first erase member function removes the element of the
container pointed to by iter. The second erase member function
removes the elements of the container in the range [first, last).
Both return an iterator that designates the first element remaining
beyond any elements removed, or end() if no such element exists.
Removing N elements causes N destructor calls and an assignment for
each of the elements between the insertion point and the nearer end
of the sequence. Removing an element at either end invalidates only
iterators and references that designate the erased elements.
Otherwise, erasing an element invalidates all iterators and
references. The clear member function calls erase( begin(), end()).
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// erase
// clear
// begin
// end
////////////////////////////////////////////////////////////////////
void main()
{
// create a and with elements 1,2,3,4 and 5
INTDEQUE a;
a.push_back(1);
a.push_back(2);
a.push_back(3);
a.push_back(4);
a.push_back(5);
//clear a
a.clear();
print_contents (a);
}
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
The sample code below illustrates how to use the deque::front and
deque::back STL functions in Visual C++.
Required Header:
< deque>
Prototype:
reference front();
const_reference front() const;
reference back();
const_reference back() const;
Description:
The member function front returns a reference to the first element
of the controlled sequence, which must be non-empty. The member
function back returns a reference to the last element of the
controlled sequence, which must be non-empty.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// front()
//
// back()
////////////////////////////////////////////////////////////////////
void main()
{
//create a with A, B, C and D
CHARDEQUE a;
a.push_back('A');
a.push_back('B');
a.push_back('C');
a.push_back('D');
CHARDEQUE::reference reffront=a.front();
CHARDEQUE::reference refback=a.back();
reffront='X';
refback='Y';
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
The contents of a : A B C D
The contents of a : X B C Y
The sample code below illustrates how to use the deque::insert STL
function in Visual C++.
Required Header:
<deque>
Prototype:
Description:
Each of these functions inserts a sequence specified by the
remaining operands after the element pointed to by iter in the
container. The first member function inserts a single element with
value x and returns an iterator that points to the newly inserted
element. The second member function inserts a repetition of n
elements of value x. The third member function inserts the sequence
[first, last).
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// insert
// begin
// end
////////////////////////////////////////////////////////////////////
void main()
{
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
Required Header:
< deque>
Prototype:
Description:
The member function operator[] returns a reference to the element
of the controlled sequence at position pos. If that position is
invalid, the behavior is undefined. The member function at returns
a reference to the element of the controlled sequence at position
pos. If that position is invalid, the function throws an object of
class out_of_range. The member function empty returns true for an
empty controlled sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// operator[]
// at
// empty
// push_back
// begin
// end
////////////////////////////////////////////////////////////////////
void main()
{
//create an empty deque a
CHARDEQUE a;
//inset A, B, C and D to a
a.push_back('A');
a.push_back('B');
a.push_back('C');
a.push_back('D');
print_contents (a,"a");
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
a is empty
a is not empty
The contents of a : A B C D
The first element of a is A
The first element of a is A
The last element of a is D
The last element of a is D
Required Header:
<deque>
Prototype:
Description:
The push_back function inserts an element with value x at the end
of the container deque. The pop_back function removes the last
element of the container deque, which must be non-empty.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// deque::push_back
//
// deque::pop_back
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <deque>
void main()
{
INTDEQUE dequetest;
dequetest.push_back(1);
dequetest.push_back(2);
dequetest.push_back(3);
printcontents (dequetest);
dequetest.pop_back();
printcontents (dequetest);
dequetest.pop_back();
printcontents (dequetest);
}
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<endl ;
}
}
Required Header:
<deque>
Prototype:
Description:
The push_front function inserts an element with value x at the
beginning of the deque container. The pop_front function removes
the first element of the deque container, which must be non-empty.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// deque::push_front
// deque::pop_front
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <deque>
void main()
{
INTDEQUE dequetest;
dequetest.push_front(1);
dequetest.push_front(2);
dequetest.push_front(3);
printcontents (dequetest);
dequetest.pop_front();
printcontents (dequetest);
dequetest.pop_front();
printcontents (dequetest);
}
{
INTDEQUE::iterator pdeque;
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<endl ;
}
}
The sample code below illustrates how to use the deque::rbegin and
deque::rend STL functions in Visual C++.
Required Header:
< deque>
Prototype:
Description:
The rbegin member function returns a reverse iterator that points
just beyond the end of the controlled sequence. Therefore, it
designates the beginning of the reverse sequence. The rend member
function returns a reverse iterator that points at the first
element of the sequence, or just beyond the end of an empty
sequence. Therefore, it designates the end of the reverse sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// rbegin
// rend
// push_back
////////////////////////////////////////////////////////////////////
void main()
{
INTDEQUE A;
A.push_back(1);
A.push_back(2);
A.push_back(3);
A.push_back(4);
A.push_back(5);
INTDEQUE::reverse_iterator rpi;
5 4 3 2 1
The sample code below illustrates how to use the deque::size and
deque::resize STL functions in Visual C++.
Required Header:
<deque>
Prototype:
Description:
The member function size returns the length of the controlled
sequence. The member function resize ensures that size() henceforth
returns n. If it must make the controlled sequence longer, it
appends elements with value x. If no value is supplied, the default
value depends upon the type. For example, if it is a deque of
chars, the default is a blank. If it is a deque of ints, the
default is zero. The member function max_size returns the length of
the longest sequence that the object can control.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// size
// resize
// max_size
// begin
// end
////////////////////////////////////////////////////////////////////
void main()
{
//create a with A, B, C and D
CHARDEQUE a;
a.push_back('A');
a.push_back('B');
a.push_back('C');
a.push_back('D');
print_contents (a,"a");
cout <<"max_size of a is " <<a.max_size() <<endl;
cout <<"size of a is " <<a.size() <<endl;
//let us resize it to 5
a.resize(5);
print_contents (a,"a");
cout <<"size of a is " <<a.size() <<endl;
cout <<"max_size of a is still " <<a.max_size() <<endl;
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
The contents of a : A B C D
max_size of a is 4294967295
size of a is 4
The contents of a : A B C D X X X X X X
size of a is 10
The contents of a : A B C D X
size of a is 5
The sample code below illustrates how to use the distance STL
function in Visual C++.
Required Header:
<iterator>
Prototype:
Description:
This function returns the distance between two iterators by
determining how many times the first iterator would need to be
incremented until it was equal to the last iterator.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : distance.cpp
//
// Functions:
//
// distance()
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <iterator>
#include <string>
void main() {
VTRLIST Vector;
VTRLIST::iterator iVector;
VTRLIST::difference_type dTheDiff;
Vector.push_back("A1");
Vector.push_back("B2");
Vector.push_back("C3");
Vector.push_back("D4");
Vector.push_back("E5");
Vector.push_back("F6");
Vector.push_back("G7");
cout << "\nUse distance() to count from the 3rd element to the e
<< endl;
dTheDiff = distance( iVector, Vector.end());
// Note that end() returns one past the end of the sequence
cout << "The distance is " << dTheDiff << endl;
The sample code below illustrates how to use the exp, log, and
log10 STL functions in Visual C++.
Required Header:
<valarray>
Prototype:
// exp
template<class T>
valarray<T> exp(const valarray<T>& x);
// log
template<class T>
valarray<T> log(const valarray<T>& x);
// log10
template<class T>
valarray<T> log10(const valarray<T>& x);
Description:
This article illustrates the use of the STL exp(), log(), and log10
() functions through sample code.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: None
//
// <filename> : main.cpp
//
// Functions:
//
// exp, log, log10
////////////////////////////////////////////////////////////////////
void main()
{
// Set val_array to contain values 1, 10, 100 for the following
DB_VARRAY val_array(ARRAY_SIZE);
for (int i = 0; i < ARRAY_SIZE; i++)
val_array[i] = pow(10, i);
// -------------------------------------------------------------
// exp() - display the content of rvalue_array
// -------------------------------------------------------------
rvalue_array = exp(val_array);
cout << "The result after calling exp():\r\n";
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << "\r\n\r\n";
// -------------------------------------------------------------
// log() - display the content of rvalue_array
// -------------------------------------------------------------
rvalue_array = log(val_array);
cout << "The result after calling log():\r\n";
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << "\r\n\r\n";
// -------------------------------------------------------------
// log10() - display the content of rvalue_array
// -------------------------------------------------------------
rvalue_array = log10(val_array);
cout << "The result after calling log10():\r\n";
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << "\r\n\r\n";
}
Size of val_array = 3
1 10 100
0 2.30259 4.60517
0 1 2
The sample code below illustrates how to use the find STL function
in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The find algorithm locates the first element in the range [first,
last) that matches value and returns the iterator positioned at the
first matching element, or last + 1 if no such element exists.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// find.cpp : Illustrates how to use the find function.
//
// Functions:
//
// find - Find the first element in a sequence that matches value
////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <iostream>
void main()
{
const int ARRAY_SIZE = 8 ;
int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } ;
int i ;
int value = 4 ;
IntArray { 1, 2, 3, 4, 4, 5, 6, 7, }
The sample code below illustrates how to use the find_if STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The find_if algorithm locates the first element in the range
[first, last) that causes the predicate to return true and returns
the iterator positioned at that element, or last if no such element
was found.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// findif.cpp : Illustrates how to use the find_if function.
//
// Functions:
//
// find_if - locate the first element in a range that satisfies
// a predicate.
////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <iostream>
void main()
{
const int ARRAY_SIZE = 8 ;
int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } ;
int *location ; // stores the position of the first
// element that is an odd number
int i ;
IntArray { 1, 2, 3, 4, 4, 5, 6, 7, }
The sample code below illustrates how to use the for_each STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The for_each algorithm calls Function F for each element in the
range [first, last) and returns the input parameter F. This
function does not modify any elements in the sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// count.cpp : Illustrates how to use the for_each function.
//
// Functions:
//
// for_each - Calls function F for every element in a range.
//
// begin - Returns an iterator that points to the first elemen
// in a sequence.
//
// end - Returns an iterator that points one past the end of
// a sequence.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
void main()
{
const int VECTOR_SIZE = 8 ;
int i ;
Numbers { 1 2 3 4 5 6 7 8 }
The sample code below illustrates how to use the Generate STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The Generate algorithm traverses the range [first, last + 1),
assigning to each element the value returned by gen. Generate
modifies the elements in the specified range.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// generate.cpp : Illustrates how to use the generate function.
//
// Functions:
//
// generate - Fill a sequence using a generator function
// Fibonacci - return the next Fibonacci number in the
// Fibonacci series.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
void main()
{
const int VECTOR_SIZE = 8 ;
Numbers { 1 1 2 3 5 8 13 21 }
The sample code below illustrates how to use the generate_n STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The generate_n algorithm traverses the range [first, first + n),
assigning to each element the value returned by gen. Note that
generate modifies the elements in the specified range.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// generate_n.cpp : Illustrates how to use the generate_n function.
//
// Functions:
//
// generate_n - Fill a specified number of elements of a sequence
// using a generator function.
//
// begin - Returns an iterator that points to the first elem
// in a sequence.
//
// end - Returns an iterator that points one past the end
// a sequence.
//
// size - Returns the length of a sequence.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
r = f1 + f2 ;
f1 = f2 ;
f2 = r ;
return f1 ;
}
void main()
{
const int VECTOR_SIZE = 15 ;
int i ;
The sample code below illustrates how to use the heap STL function
in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
A heap is a sequence of elements organized like a binary tree. Each
heap element corresponds to a tree node. The first value in the
sequence [first..last) is the root, and is the largest value in the
heap. Every element in the heap satisfies the following: Every
element is less than or equal to its parent. The largest element is
stored in the root, and all children hold progressively smaller
values. The make_heap function converts the range [first..last)
into a heap. The sort_heap function sorts a "heapified" sequence
that was created using the make_heap function. The push_heap
function inserts a new value into the heap. The pop_heap function
swaps the first and last elements in the heap specified by [first,
last), then reduces the length of the sequence by one before
restoring the heap property. The non-predicate versions of the heap
functions use the operator< for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// heap_functions.cpp : Illustrates how to use the
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
IntVectorIt it ;
Numbers { 4 10 70 10 30 69 96 100 }
Numbers { 100 30 96 10 4 69 70 10 }
Numbers { 4 10 10 30 69 70 96 100 }
Numbers { 100 69 96 30 4 70 10 10 7 }
Numbers { 96 69 70 30 4 7 10 10 100 }
The sample code below illustrates how to use the predicate versions
of the heap STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
A heap is a sequence of elements organized like a binary tree. Each
heap element corresponds to a tree node. The first value in the
sequence [first..last) is the root, and is ordered by the
predicate. For example, if the predicate is greater, every element
in the heap satisfies the following: Every element is greater than
or equal to its parent. The smallest element is stored in the root,
and all children hold progressively larger values. The make_heap
function converts the range [first..last) into a heap. The
sort_heap function sorts a "heapified" sequence that was created
using the make_heap function. The push_heap function inserts a new
value into the heap. The pop_heap function swaps the first and last
elements in the heap specified by [first, last), then reduces the
length of the sequence by one before restoring the heap property.
The predicate versions of the heap functions use the compare
function for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// heap_functions.cpp : Illustrates how to use the predicate version
// of the make_heap, sort_heap, push_heap
// and pop_heap functions.
//
// Functions:
//
// make_heap : Convert a sequence to a heap.
// sort_heap : Sort a heap.
// push_heap : Insert an element in a heap.
// pop_heap : Remove the top element from a heap.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
IntVectorIt it ;
Numbers { 4 10 70 10 30 69 96 100 }
Numbers { 4 7 10 30 100 10 70 96 69 }
The sample code below illustrates how to use the includes STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The includes algorithm searches for one sequence of values in
another sequence of values. includes returns true if every element
in the range [first2..last2) is in the sequence [first1..last1).
This version of includes assumes that both sequences are sorted
using operator<.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// includesP.cpp : Illustrates how to use the includes function.
//
// Functions:
//
// includes - Search for one sequence in another.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <deque>
void main()
{
const int VECTOR_SIZE = 5 ;
StringVector CartoonVector(VECTOR_SIZE) ;
StringDeque CartoonDeque ;
The sample code below illustrates how to use the predicate version
of the includes STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The includes algorithm searches for one sequence of values in
another sequence of values. includes returns true if every element
in the range [first2..last2) is in the sequence [first1..last1).
This version of includes assumes that both sequences are sorted
using the compare function.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// includesP.cpp : Illustrates how to use the predicate version of
// includes function.
//
// Functions:
//
// includes - Search for one sequence in another.
// string_compare - Compare strings, return true if
// s1 < s2.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <deque>
StringVector CartoonVector(VECTOR_SIZE) ;
StringDeque CartoonDeque ;
CartoonVector[4] = "Goofy" ;
The sample code below illustrates how to use the inner_product STL
function in Visual C++.
Required Header:
<numeric>
Prototype:
Description:
inner_product computes its result by initializing the accumulator
acc with init and then modifying it with: acc = acc + (*i1) * (*i2)
- or - acc = binary_op1(acc, binary_op2(*i1, *i2)) for every
iterator i1 in the range [first, last) and iterator i2 in the range
[first2, first2 + (last - first)) in order.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// inner_product.cpp : Demonstrates the use of inner_product().
//
// Description of
// inner_product(first,last,first2,init)
// inner_product(first,last,first2,init,binary_op1,binary_op
//
// Computes its result by initializing the accumulator acc with i
// acc = init
// and then modifying it with
// acc = acc + (*i1) * (*i2)
// or
// acc = binary_op1(acc, binary_op2(*i1, *i2))
// for every iterator i1 in the range [first, last) and
// iterator i2 in the range [first2, first2 + (last - first))
// in order.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
void main ()
{
FloatOstreamIt itOstream(cout," ");
Array 1: 1 2 3 4 5
Array 2: 1 4 9 16 25
The inner product (S.O.P) of Array1 and Array2 is 225
The inner product (P.O.S.) of Array1 and Array2 is 86400
The sample code below illustrates how to use the inplace_merge STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
template<class BidirectionalIterator>
inline void inplace_merge(BidirectionalIterator first, Bidirect
Description:
The inplace_merge algorithm merges two sorted sub-sequences:
[first..middle) and [middle..last) in place into a single sorted
sequence [first..last). This version assumes that the ranges
[first..middle) and [middle..last) are sorted using operator<. If
both ranges contain equal values, the value from the first range
will be stored first.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// inplace_merge.cpp : Illustrates how to use the inplace_merge
// function.
//
// Functions:
//
// inplace_merge : Merge two sorted sub-sequences in place into a
// single sorted list.
//
// begin - Returns an iterator that points to the first element in
// sequence.
//
// end - Returns an iterator that points one past the end of a seq
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 70 10 30 69 96 100 }
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the predicate version
of the inplace_merge STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The inplace_merge algorithm merges two sorted sub-sequences:
[first..middle) and [middle..last) in place into a single sorted
sequence [first..last). This version assumes that the ranges
[first..middle) and [middle..last) are sorted using the compare
function. If both ranges contain equal values, the value from the
first range will be stored first.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// inplace_mergeP.cpp : Illustrates how to use the predicate version
// the inplace_merge function.
//
// Functions:
//
// inplace_merge - Merge two sorted sub-sequences in place into a
// single sorted list using the compare function.
//
// begin - Returns an iterator that points to the first element i
// sequence.
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 70 10 30 69 96 100 }
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the iter_swap STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The iter_swap algorithm swaps two elements represented by two
iterators.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// iter_swap.cpp : Illustrates how to use the iter_swap function.
//
// Functions:
//
// iter_swap - Swap two elements in a sequence represented by
// two iterators.
//
// begin - Returns an iterator that points to the first eleme
// in a sequence.
//
// end - Returns an iterator that points one past the end o
// a sequence.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
void main()
{
const int VECTOR_SIZE = 8 ;
The sample code below illustrates how to use the list::assign STL
function in Visual C++.
Required Header:
<list>
Prototype:
Description:
The first member function replaces the sequence controlled by *this
with the sequence [first, last). The second member function
replaces the sequence controlled by *this with a repetition of n
elements of value x. The third member function removes the element
of the controlled sequence pointed to by it. The fourth member
function removes the elements of the controlled sequence in the
range [first, last). Both return an iterator that designates the
first element remaining beyond any elements removed, or end() if no
such element exists. The last member function returns true for an
empty controlled sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// assign.cpp : Shows the various ways to assign and erase elements
// from a list<T>.
//
// Functions:
//
// list::assign
// list::empty
// list::erase
////////////////////////////////////////////////////////////////////
#include <list>
#include <iostream>
void main()
{
LISTINT listOne;
LISTINT listAnother;
LISTINT::iterator i;
listAnother.push_front(4);
listAnother.assign(listOne.begin(), listOne.end());
// 1 2 3
for (i = listAnother.begin(); i != listAnother.end(); ++i)
cout << *i << " ";
cout << endl;
listAnother.assign(4, 1);
// 1 1 1 1
for (i = listAnother.begin(); i != listAnother.end(); ++i)
cout << *i << " ";
cout << endl;
listAnother.erase(listAnother.begin());
// 1 1 1
for (i = listAnother.begin(); i != listAnother.end(); ++i)
cout << *i << " ";
cout << endl;
listAnother.erase(listAnother.begin(), listAnother.end());
if (listAnother.empty())
cout << "All gone\n";
}
1 2 3
1 1 1 1
1 1 1
All gone
The sample code below illustrates how to use the list::back and
list::front STL functions in Visual C++.
Required Header:
<list>
Prototype:
reference back();
const_reference back() const;
reference front();
const_reference front() const;
void pop_back();
void pop_front();
void push_back(const T& x);
void push_front(const T& x);
Description:
The member function back returns a reference to the last element of
the controlled sequence. The member function front returns a
reference to the first element of the controlled sequence. The
member function pop_back removes the last element of the controlled
sequence. The member function pop_front removes the first element
of the controlled sequence. All the above functions require that
the controlled sequence be non-empty. The member function push_back
inserts an element with value x at the end of the controlled
sequence. The member function push_front inserts an element with
value x at the beginning of the controlled sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// liststck.cpp : This example shows how to use the various stack
// like functions of list.
//
// Functions:
//
// list::back
// list::front
// list::pop_back
// list::pop_front
// list::push_back
// list::push_front
////////////////////////////////////////////////////////////////////
#include <list>
#include <string>
#include <iostream>
void main()
{
LISTSTR test;
test.push_back("back");
test.push_front("middle");
test.push_front("front");
// front
cout << test.front() << endl;
// back
cout << test.back() << endl;
test.pop_front();
test.pop_back();
// middle
cout << test.front() << endl;
}
front
back
middle
The sample code below illustrates how to use the list::insert STL
function in Visual C++.
Required Header:
<list>
Prototype:
Description:
Each of the member functions inserts, after the element pointed to
by it in the controlled sequence, a sequence specified by the
remaining operands. The first member function inserts a single
element with value x and returns an iterator that points to the
newly inserted element. The second member function inserts a
repetition of n elements of value x. The last two member functions
insert the sequence [first, last).
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// insert.cpp : Shows the various ways to insert elements into a
// list<T>.
//
// Functions:
//
// list::insert
////////////////////////////////////////////////////////////////////
#include <list>
#include <iostream>
void main()
{
int rgTest1[] = {5,6,7};
int rgTest2[] = {10,11,12};
LISTINT listInt;
LISTINT listAnother;
LISTINT::iterator i;
// 1 2 3
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
cout << endl;
// Insert 3 fours
listInt.insert (listInt.end(), 3, 4);
// 1 2 3 4 4 4
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
cout << endl;
// 1 2 3 4 4 4 5 6 7
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
cout << endl;
// 1 2 3 4 4 4 5 6 7 10 11 12
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
cout << endl;
}
1 2 3
1 2 3 4 4 4
1 2 3 4 4 4 5 6 7
1 2 3 4 4 4 5 6 7 10 11 12
The sample code below illustrates how to use the list::list STL
function in Visual C++.
Required Header:
<list>
Prototype:
Description:
The first constructor specifies an empty initial controlled
sequence. The second constructor specifies a repetition of n
elements of value x. The third constructor specifies a copy of the
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// list.cpp : demonstrates the different constructors for list<T>
//
// Functions:
//
// list::list
////////////////////////////////////////////////////////////////////
#include <list>
#include <string>
#include <iostream>
test.insert(test.end(), "one");
test.insert(test.end(), "two");
// one two
for (i = test.begin(); i != test.end(); ++i)
cout << *i << " ";
cout << endl;
// one two
for (i = test2.begin(); i != test2.end(); ++i)
cout << *i << " ";
cout << endl;
// three three
for (i = test4.begin(); i != test4.end(); ++i)
cout << *i << " ";
cout << endl;
}
one two
one two
three three three
three three
The sample code below illustrates how to use the lower_bound STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The lower_bound algorithm returns the first location in the
sequence that value can be inserted such that the order of the
sequence is maintained. lower_bound returns an iterator positioned
at the location that value can be inserted in the range
[first..last), or returns last if no such position exists.
lower_bound assumes the range [first..last) is sorted using
operator<.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// lower_bound.cpp : Illustrates how to use the lower_bound
// function.
//
// Functions:
//
// lower_bound : Return the lower bound within a range.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the the predicate
version of the lower_bound STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The lower_bound algorithm returns the first location in the
sequence that value can be inserted such that the order of the
sequence is maintained. lower_bound returns an iterator positioned
at the location that value can be inserted in the range
[first..last), or returns last if no such position exists. This
version assumes the range [first..last) is sorted sequentially
using the compare function.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// lower_bound.cpp : Illustrates how to use the lower_bound
// function.
//
// Functions:
//
// lower_bound : Return the lower bound within a range.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the make_pair STL
function in Visual C++.
Required Header:
<utility>
Prototype:
Description:
The make_pair function creates a pair structure that contains two
data elements of any type.
Sample Code:
////////////////////////////////////////////////////////////////////
// Compile options needed: none
//
// mkpair.cpp: Illustrates how to use the make_pair function.
//
// Functions: make_pair - creates an object pair containing two data
// elements of any type.
////////////////////////////////////////////////////////////////////
#include <utility>
#include <iostream>
void main(void)
{
PAIR_IF pair1=make_pair(18,3.14f);
cout << pair1.first << " " << pair1.second << endl;
pair1.first=10;
pair1.second=1.0f;
cout << pair1.first << " " << pair1.second << endl;
}
18 3.14
10 1
Required Header:
<map>
Prototype:
iterator map::end();
Description:
The end() function returns an iterator that points one past the end
of a sequence. Find returns an iterator that designates the first
element whose sort key equals key. If no such element exists, the
iterator equals end(). If the key does not already exist, insert
will add it to the sequence and return pair<iterator, true>. If the
key already exists, insert does not add it to the sequence and
returns pair <iterator, false>. The following sample creates a map
of ints to strings. In this case, the mapping is from digits to
their string equivalents (1 -> "One", 2 -> "Two", etc.). The
program reads a number from the user, finds the word equivalent for
each digit (using the map), and prints the number back as a series
of words. For example, if the user enters 25463, the program
responds with: Two Five Four Six Three.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: None
//
// <filename> : main.cpp
//
// Functions:
//
// end
// find
// insert
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
void main()
{
// 1. Create a map of ints to strings
INT2STRING theMap;
INT2STRING::iterator theIterator;
string theString = "";
int index;
Required Header:
<algorithm>
Prototype:
template<class InputIterator>
inline InputIterator max_element(InputIterator first, InputIter
Description:
The max_element algorithm returns the location of the maximum
element in the sequence [first, last). The non-predicate version of
max_element uses operator< for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// max_element.cpp : Illustrates how to use the max_element
// function.
//
// Functions:
//
// max_element : Return the maximum element within a range.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the predicate version
of the max_element STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The max_element algorithm returns the location of the maximum
element in the sequence [first, last). The predicate version of
max_element uses the compare function for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// max_element.cpp : Illustrates how to use the predicates version
// of the max_element function.
//
// Functions:
//
// max_element : Return the maximum element within a range.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
Required Header:
<map>
Prototype:
Description:
The following sample creates a map of strings to ints and fills it
first with a map of month names to month numbers, then empties and
refills it with a map of weekday names to corresponding ints.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: None
//
// <filename> : main.cpp
//
// Functions: iterator map::max_size();
// void clear() const;
// bool empty() const;
// iterator erase(iterator first, iterator last);
// size_type size() const;
// A::reference operator[](const Key& key);
// iterator map::begin();
// iterator map::end();
// iterator map::find(const Key& key);
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
void main()
{
STRING2INT MyMap;
STRING2INT::iterator MyIterator;
string MyBuffer;
if(!MyMap.empty())
cout << "MyMap has " << MyMap.size() << " entries" << endl;
else
cout << "MyMap is empty" << endl;
cout << "Entering new entries in MyMap" << endl;
// Fill in MyMap with the months of the year, mapped to their nu
// January - 1, February - 2, etc. using operator[].
MyMap["January"] = 1;
MyMap["February"] = 2;
MyMap["March"] = 3;
MyMap["April"] = 4;
MyMap["May"] = 5;
MyMap["June"] = 6;
MyMap["July"] = 7;
MyMap["August"] = 8;
MyMap["September"] = 9;
MyMap["October"] = 10;
MyMap["November"] = 11;
MyMap["December"] = 12;
if(!MyMap.empty())
cout << "MyMap has " << MyMap.size() << " entries" << endl;
else
cout << "MyMap is empty" << endl;
// Ask the user for a month of the year and print the number
// that corresponds to the month entered
//MyIterator = MyMap.end();
while(MyIterator == MyMap.end()){
cout << "Enter a Month :";
cin >> MyBuffer;
if((MyIterator = MyMap.find(MyBuffer)) != MyMap.end())
cout << (*MyIterator).first << " is Month Number "
<< (*MyIterator).second << endl;
else
cout << "Enter a Valid Month (example: March)" << endl;
}
if(!MyMap.empty())
cout << "MyMap has " << MyMap.size() << " entries" << endl;
else
cout << "MyMap is empty" << endl;
cout << "Entering new entries in MyMap" << endl;
// Fill MyMap with the days of the week, each mapped to an int
MyMap["Monday"] = 1;
MyMap["Tuesday"] = 2;
MyMap["Wednesday"] = 3;
MyMap["Thursday"] = 4;
MyMap["Friday"] = 5;
MyMap["Saturday"] = 6;
MyMap["Sunday"] = 7;
if(!MyMap.empty())
cout << "MyMap has " << MyMap.size() << " entries" << endl;
else
cout << "MyMap is empty" << endl;
// Ask the user for a day of the week and print the number
// that corresponds to the day entered
MyIterator = MyMap.end();
while(MyIterator == MyMap.end()){
cout << "Enter a Day of the Week:";
cin >> MyBuffer;
if((MyIterator = MyMap.find(MyBuffer)) != MyMap.end())
cout << (*MyIterator).first << " is Day Number "
<< (*MyIterator).second << endl;
else
cout <<"Enter a Valid Day of the Week(example: Monday)"<
}
// Now clear MyMap again - this time using erase instead of clear
MyMap.erase(MyMap.begin(), MyMap.end());
if(!MyMap.empty())
cout << "MyMap has " << MyMap.size() << " entries" << endl;
else
cout << "MyMap is empty" << endl;
The sample code below illustrates how to use the merge STL function
in Visual C++.
Required Header:
<algorithm>
Prototype:
template<class InputIterator1,
class InputIterator2,
Description:
The merge algorithm merges two sorted sequences: [first1..last1)
and [first2..last2) into a single sorted sequence starting at
result. This version assumes that the ranges [first1..last1) and
[first2..last2) are sorted using operator<. If both ranges contain
equal values, the value from the first range will be stored first.
The result of merging overlapping ranges is undefined.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// merge.cpp : Illustrates how to use the merge
// function.
//
// Functions:
//
// merge : Merge two sorted sequences
// into a single sorted list.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
void main()
{
const int MAX_ELEMENTS = 8 ;
IntVector NumbersVector(MAX_ELEMENTS) ;
IntList NumbersList ;
IntDequeIt itd ;
NumbersVector { 4 10 10 30 69 70 96 100 }
NumbersList { 0 1 2 3 4 5 6 7 }
NumbersDeque { 0 1 2 3 4 4 5 6 7 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the predicate version
of the merge STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
template<class InputIterator1,
class InputIterator2,
class OutputIterator
class Compare> inline
OutputIterator merge( InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2
OutputIterator result,
Compare compare )
Description:
The merge algorithm merges two sorted sequences: [first1..last1)
and [first2..last2) into a single sorted sequence starting at
result. This version assumes that the ranges [first1..last1) and
[first2..last2) are sorted using the compare function. If both
ranges contain equal values, the value from the first range will be
stored first. The result of merging overlapping ranges is
undefined.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// merge.cpp : Illustrates how to use predicate version of the merge
// function.
//
// Functions:
//
// merge : Merge two sorted sequences
// into a single sorted list.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
void main()
{
const int MAX_ELEMENTS = 8 ;
IntVector NumbersVector(MAX_ELEMENTS) ;
IntList NumbersList ;
IntDequeIt itd ;
NumbersVector { 4 10 10 30 69 70 96 100 }
NumbersList { 0 1 2 3 4 5 6 7 }
NumbersDeque { 0 1 2 3 4 4 5 6 7 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the min_element STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The min_element algorithm returns the location of the minimum
element in the sequence [first, last). The non-predicate version of
min_element uses operator< for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// min_element.cpp : Illustrates how to use the min_element
// function.
//
// Functions:
//
// min_element - Return the minimum element within a range.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the predicate version
of the min_element STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The min_element algorithm returns the location of the minimum
element in the sequence [first, last). The predicate version of
min_element uses the compare function for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// min_element.cpp : Illustrates how to use the predicates version
// of the min_element function.
//
// Functions:
//
// min_element : Return the minimum element within a range.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the new operator.
Required Header:
<new>
Prototype:
Description:
The first operator new will attempt to allocate memory and if it
fails, will throw an exception. The second operator new accepts a
second parameter of type nothrow. This parameter indicates that if
the allocation fails, it should return NULL and not throw an
exception. The third operator new will allocate memory for an array
of that type and if it fails, will throw an exception.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : newop.cpp
//
// Functions:
//
// void *operator new(size_t n)
//
// void *operator new(size_t n, const nothrow&)
//
// void *operator new[](size_t n);
////////////////////////////////////////////////////////////////////
#include <new>
#include <iostream>
class BigClass {
public:
BigClass() {};
~BigClass(){}
double BigArray[99999999];
};
void main()
{
try {
BigClass * p = new BigClass;
}
catch( bad_alloc a) {
const char * temp = a.what();
cout << temp << endl;
cout << "Threw a bad_alloc exception" << endl;
}
BigClass * q = new(nothrow) BigClass;
if ( q == NULL )
cout << "Returned a NULL pointer" << endl;
try {
BigClass * r = new BigClass[3];
}
catch( bad_alloc a) {
const char * temp = a.what();
cout << temp << endl;
cout << "Threw a bad_alloc exception" << endl;
}
}
bad allocation
Threw a bad_alloc exception
Returned a NULL pointer
bad allocation
Threw a bad_alloc exception
Required Header:
<algorithm>
Prototype:
Description:
The next_permutation algorithm changes the order of the elements in
the range [first, last) to the next lexicographic permutation and
returns true. If there is no next_permutation, it arranges the
sequence to be the first permutation and returns false. IMPORTANT:
The next_permutation algorithm assumes the sequence is sorted in
ascending order using operator<. The non-predicate version uses the
operator< to order the permutations.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// next_permutation.cpp : Illustrates how to use the
// next_permutation function.
//
// Functions:
//
// next_permutation : Change the order of the sequence to the
// next lexicograhic permutation.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 3 ;
StrVector Pattern(VECTOR_SIZE) ;
// element of Pattern
The sample code below illustrates how to use the predicate version
of the next_permutation STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The next_permutation algorithm changes the order of the elements in
the range [first, last) to the next lexicographic permutation and
returns true. If there is no next_permutation, it arranges the
sequence to be the first permutation and returns false. NOTE: The
next_permutation algorithm assumes that the sequence is sorted in
ascending order using the compare function. The non-predicate
version uses the compare function to order the permutations.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// next_permutation.cpp : Illustrates how to use the predicate versi
// of the next_permutation function.
//
// Functions:
//
// next_permutation : Change the order of the sequence to the
// next lexicograhic permutation.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 3 ;
StrVector Pattern(VECTOR_SIZE) ;
The sample code below illustrates how to use the nth_element STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The nth_element algorithm partitions the sequence [first..last) on
the value referenced by nth. All the elements less than or equal to
the value are placed before value and all elements greater than
value are placed after value in the sequence. The non-predicate
version of nth_element uses operator< for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// nth_element.cpp : Illustrates how to use the nth_element
// function.
//
// Functions:
//
// nth_element : Partition the elements in a sequence by its nth
// element.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers[1] = 10;
Numbers[2] = 70 ;
Numbers[3] = 30 ;
Numbers[4] = 10;
Numbers[5] = 69 ;
Numbers[6] = 96 ;
Numbers[7] = 100;
Numbers { 4 10 70 30 10 69 96 100 }
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the predicate version
of the nth_element STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The nth_element algorithm partitions the sequence [first..last) on
the value referenced by nth. All the elements less than or equal to
the value are placed before value and all elements greater than
value are placed after value in the sequence. The predicate version
of nth_element uses the compare function for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// nth_element.cpp : Illustrates how to use the predicate version
// of the nth_element function.
//
// Functions:
//
// nth_element : Partition the elements in a sequence by its nth
// element.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers[1] = 10;
Numbers[2] = 70 ;
Numbers[3] = 30 ;
Numbers[4] = 10;
Numbers[5] = 69 ;
Numbers[6] = 96 ;
Numbers[7] = 100;
Numbers { 4 10 70 30 10 69 96 100 }
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the members of the
numeric_limits class in Visual C++.
Required Header:
<limits>
Description:
To reference one of the members of this class, you need to specify
the type that you want to obtain information about and the member
name. The return will either be a value of 1 for true or 0 for
false. For example, numeric_limits<int>::min() will return the
minimum value for an int. NOTE: Some of the members are valid only
for certain types. Please refer to the Online Help to determine if
a member is valid only for a certain type.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : Numeric.cpp
//
// Variables and Functions:
//
// has_denorm
// has_denorm_loss
// has_infinity
// has_quiet_NaN
// has_signaling_NaN
// is_bounded
// is_exact
// is_iec559
// is_integer
// is_modulo
// is_signed
// is_specialized
// tinyness_before
// traps
// round_style
// digits
// digits10
// max_exponent
// max_exponent10
// min_exponent
// min_exponent10
// radix;
// denorm_min()
// epsilon()
// infinity()
// max()
// min()
// quiet_ NaN()
// round_error()
// signaling_NaN()
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <limits>
void main() {
cout << " 1 The minimum value for char is " <<
(int)numeric_limits<char>::min() << endl;
cout << " 2 The minimum value for int is " <<
numeric_limits<int>::min() << endl;
cout << " 3 The maximum value for char is " <<
(int)numeric_limits<char>::max() << endl;
cout << " 4 The maximum value for int is " <<
numeric_limits<int>::max() << endl;
cout << " 5 The number of bits to represent a char is " <<
numeric_limits<char>::digits << endl;
cout << " 6 The number of bits to represent an int is " <<
numeric_limits<int>::digits << endl;
cout <<" 7 The number of digits representable in base 10 for flo
<< numeric_limits<float>::digits10 << endl;
cout << " 8 Is a char signed? " <<
numeric_limits<char>::is_signed << endl;
cout << " 9 Is an unsigned integer signed? " <<
numeric_limits<unsigned int>::is_signed << endl;
cout << "10 Is a integer an integer? " <<
numeric_limits<int>::is_integer << endl;
cout << "11 Is a float an integer? " <<
numeric_limits<float>::is_integer << endl;
cout << "12 Is a integer exact? " <<
numeric_limits<int>::is_exact << endl;
cout << "13 Is a float exact? " <<
numeric_limits<float>::is_exact << endl;
cout << "14 The radix for float is " <<
numeric_limits<float>::radix << endl;
cout << "15 The epsilon for float is " <<
numeric_limits<float>::epsilon() << endl;
cout << "16 The round error for float is " <<
numeric_limits<float>::round_error() << endl;
cout << "17 The minimum exponent for float is " <<
numeric_limits<float>::min_exponent << endl;
cout << "18 The minimum exponent in base 10 " <<
numeric_limits<float>::min_exponent10 << endl;
cout << "19 The maximum exponent is " <<
numeric_limits<float>::max_exponent << endl;
cout << "20 The maximum exponent in base 10 " <<
numeric_limits<float>::max_exponent10 << endl;
cout << "21 Can float represent positive infinity? " <<
numeric_limits<float>::has_infinity << endl;
cout << "22 Can double represent positive infinity? " <<
numeric_limits<double>::has_infinity << endl;
cout << "23 Can int represent positive infinity? " <<
numeric_limits<int>::has_infinity << endl;
cout << "24 Can float represent a NaN? " <<
numeric_limits<float>::has_quiet_NaN << endl;
cout << "25 Can float represent a signaling NaN? " <<
numeric_limits<float>::has_signaling_NaN << endl;
cout << "26 Does float allow denormalized values? " <<
numeric_limits<float>::has_denorm << endl;
cout << "27 Does float detect denormalization loss? " <<
numeric_limits<float>::has_denorm_loss << endl;
cout << "28 Representation of positive infinity for float " <<
numeric_limits<float>::infinity() << endl;
cout << "29 Representation of quiet NaN for float " <<
numeric_limits<float>::quiet_NaN() << endl;
cout << "30 Minimum denormalized number for float " <<
numeric_limits<float>::denorm_min() << endl;
cout << "31 Minimum positive denormalized value for float " <<
numeric_limits<float>::denorm_min() << endl;
cout << "32 Does float adhere to IEC 559 standard? " <<
numeric_limits<float>::is_iec559 << endl;
cout << "33 Is float bounded? " <<
numeric_limits<float>::is_bounded << endl;
cout << "34 Is float modulo? " <<
numeric_limits<float>::is_modulo << endl;
cout << "35 Is int modulo? " <<
numeric_limits<float>::is_modulo << endl;
cout << "36 Is trapping implemented for float? " <<
numeric_limits<float>::traps << endl;
cout << "37 Is tinyness detected before rounding? " <<
numeric_limits<float>::tinyness_before << endl;
cout << "38 What is the rounding style for float? " <<
(int)numeric_limits<float>::round_style << endl;
cout << "39 What is the rounding style for int? " <<
(int)numeric_limits<int>::round_style << endl;
cout << "40 How does a float represent a signaling NaN? " <<
numeric_limits<float>::signaling_NaN() << endl;
cout << "41 Is int specialized? " <<
numeric_limits<float>::is_specialized << endl;
}
The sample code below illustrates how to use the operator == and
operator < deque STL functions in Visual C++.
Required Header:
< deque>
Prototype:
Description:
The first template function overloads operator== to compare two
objects of template class deque. The function returns: lhs.size()
== rhs.size() && equal(lhs. begin(), lhs. end(), rhs.begin()). For
equality, the number of elements must be equal in both deque
objects. The second template function overloads operator< to
compare two objects of template class deque. The function returns:
lexicographical_compare(lhs. begin(), lhs. end(), rhs.begin(),
rhs.end()). Because lexicographic (as in a dictionary) compare is
used, the number of elements does not matter while using operator<.
In the sample code, adding a line of code while creating the b
object, such as b.push_front('D');, will make b greater than a.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// deque.cpp :
//
// Functions:
//
// ==
// <
//
////////////////////////////////////////////////////////////////////
void main()
{
//create a with 3 A's
CHARDEQUE a(3,'A');
a.push_front('C');
//compare a and b
if (a==b)
cout <<"a is equal to b"<<endl;
else if(a<b)
cout <<"a is less than b"<<endl;
else
cout <<"a is greater than b" <<endl;
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
The contents of a : C A A A
The contents of b : B B B B B B
a is greater than b
The contents of a : B B B B B B
The contents of b : B B B B B B
a is equal to b
The sample code below illustrates how to use the pair logical
operator STL function in Visual C++.
Required Header:
< utility >
Prototype:
Description:
The functions are described in the comments section of the sample.
Sample Code:
/////////////////////////////
// Compile options needed: none
//
// paircomp.cpp : Illustrates several comparison
// operators used to compare two
// pair objects.
//
// Functions:
//
// operator== - returns true if two pair objects are identical.
//
// operator!= - returns true if two pair objects are not identica
//
// operator< - returns true for (A < B) if pair object A is less
// than pair object B.
//
// operator<= - returns true for (A <= B) if pair object A is les
// than or equal to pair object B.
//
// operator> - returns true for (A > B) if pair object A is grea
// than pair object B.
//
// operator>= - returns true for (A >= B) if pair object A is gre
// than or equal to pair object B.
/////////////////////////////
#include <iostream>
#include <utility>
void main(void)
{
PAIR_IF A(10,3.14);
PAIR_IF B(18,3.14);
PAIR_IF C(10,6.28);
PAIR_IF D(10,3.14);
cout << "A = ( " << A.first << " , " << A.second << " )" << endl;
cout << "B = ( " << B.first << " , " << B.second << " )" << endl;
cout << "C = ( " << C.first << " , " << C.second << " )" << endl;
cout << "D = ( " << D.first << " , " << D.second << " )" << endl;
/* operator== */
if (A==D)
cout << "A and D are equal" << endl;
else
cout << "A and D are not equal" << endl;
/* operator!= */
if (B!=C)
cout << "B and C are not equivalent" << endl;
else
cout << "B and C are equivalent" << endl;
/* operator> */
if (A>C)
cout << "A is greater than C" << endl;
else
cout << "A is not greater than C" << endl;
/* operator>= */
if (A>=C)
cout << "A is greater than or equal to C" << endl;
else
cout << "A is not greater than or equal to C" << endl;
/* operator< */
if (C<D)
cout << "C is less than D" << endl;
else
cout << "C is not less than D" << endl;
/* operator<= */
if (C<D)
cout << "C is less than or equal to D" << endl;
else
cout << "C is not less than or equal to D" << endl;
}
A = ( 10 , 3.14 )
B = ( 18 , 3.14 )
C = ( 10 , 6.28 )
D = ( 10 , 3.14 )
A and D are equal
B and C are not equivalent
A is not greater than C
A is not greater than or equal to C
C is not less than D
C is not less than or equal to D
The sample code below illustrates how to use the partial_sort STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The partial_sort algorithm sorts the smallest N elements, where N =
middle - first of the sequence [first, last). The remaining
elements end up in the range [middle..last) in an undefined order.
The non-predicate version of partial_sort uses operator< for
comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// partial_sort.cpp : Illustrates how to use the partial_sort
// function.
//
// Functions:
//
// partial_sort : Sort the smallest N elements in a sequence.
// Copyright (c) 1996 Microsoft Corporation. All rights reserved.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 70 30 10 69 96 7 }
Numbers { 4 7 10 10 70 69 96 30 }
Required Header:
<algorithm>
Prototype:
Description:
The partial_sort_copy algorithm sorts the smallest N elements,
where N = min((last1 - first1), (last2 - first2)), of the sequence
[first1, last1) and copies the results to the sequence [first2,
first2 + N]. The non-predicate version of partial_sort_copy uses
operator< for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// partial_sort_copy.cpp : Illustrates how to use the partial_sort_c
// function.
//
// Functions:
//
// partial_sort_copy : Sort the smallest N elements in a sequence
// and copy the resulting sequence
// to another sequence.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
IntVector Result(4) ;
Numbers { 4 10 70 30 10 69 96 7 }
Numbers { 4 10 70 30 10 69 96 7 }
Result { 4 7 10 10 }
The sample code below illustrates how to use the predicate version
of the partial_sort_copy STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The partial_sort_copy algorithm sorts the smallest N elements,
where N = min((last1 - first1), (last2 - first2)), of the sequence
[first1, last1), and copies the results to the sequence [first2,
first2 + N]. The predicate version of partial_sort_copy uses the
compare function for comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// partial_sort_copyP.cpp : Illustrates how to use the predicate ver
// of the partial_sort_copy function.
//
// Functions:
//
// partial_sort_copy : Sort the smallest N elements in a sequence
// and copy the resulting sequence
// to another sequence.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
IntVector Result(4) ;
Numbers { 4 10 70 30 10 69 96 7 }
Numbers { 4 10 70 30 10 69 96 7 }
Result { 4 7 10 10 }
The sample code below illustrates how to use the predicate version
of the partial_sort STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The partial_sort algorithm sorts the smallest N elements, where N =
middle - first of the sequence [first, last). The remaining
elements end up in the range [middle..last) in an undefined order.
The predicate version of partial_sort uses the compare function for
comparisons.
Sample Code:
////////////////////////////////////////////////////////////////////
//
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 70 30 10 69 96 7 }
Numbers { 4 7 10 10 70 69 96 30 }
The sample code below illustrates how to use the partial_sum STL
function in Visual C++.
Required Header:
<numeric>
Prototype:
Description:
Assigns to every iterator i in the range [result,result + (last -
first)) a value correspondingly equal to ((...(*first + *(first +
1)) + ...) + *(first + (i - result))) - or - binary_op(binary_op
(..., binary_op(*first, *(first + 1)),...), *(first + (i -
result))). In other words, *(result+i) = init + *(first+0) + *
(first+1) + ... + *(first+i).
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// partial_sum.cpp : Demonstrates the use of partial_sum().
//
// Description of partial_sum(first,last,first2,init)
// partial_sum(first,last,first2,init,binary_op):
//
// Assigns to every iterator i in the range
// [result,result + (last - first)) a value correspondingly equal
// ((...(*first + *(first + 1)) + ...) + *(first + (i - result)))
//
// - or -
//
// binary_op(binary_op(..., binary_op(*first, *(first + 1)),...
// *(first + (i - result)))
//
// In other words,
// *(result+i) = init + *(first+0) + *(first+1) + ... + *(first+i
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
void main ()
{
IntOstreamIt itOstream(cout," ");
// The result array must be at least the same size as the data a
IntArray rgIresult(rgI.size());
Array: 1 2 3 4 5 6 7 8 9 10
Array of partial sums: 1 3 6 10 15 21 28 36 45 55
Array of partial products: 1 3 9 33 153 873 5913 46233 409113 403791
The sample code below illustrates how to use the partition STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The partition algorithm arranges elements in the range [first,
last) such that the elements for which predicate returns true are
before the elements for which predicate returns false. The
algorithm returns an iterator positioned at the first element for
which predicate returns false.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// partition.cpp : Illustrates how to use the partition function.
//
// Functions:
//
// partition - Partition a range using a predicate.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
Required Header:
<algorithm>
Prototype:
Description:
The prev_permutation algorithm changes the order of the elements
the range [first, last), to the previous lexicographic permutation
and returns true. If there is no prev_permutation, it arranges the
sequence to be the first permutation and returns false. IMPORTANT:
The prev_permutation algorithm assumes the sequence is sorted in
descending order using operator<. The non-predicate version uses
the operator< to order the permutations.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// prev_permutation.cpp : Illustrates how to use the prev_permutatio
// function.
//
// Functions:
//
// prev_permutation : Change the order of the sequence to the
// previous lexicographic permutation.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 3 ;
StrVector Pattern(VECTOR_SIZE) ;
Required Header:
<queue>
Prototype:
priority_queue::push();
priority_queue::pop();
priority_queue::empty();
priority_queue::top();
priority_queue::size();
Description:
The sample shows priority_queue implementation using deque and
vector containers.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : priority_queue.cpp
//
// Functions:
//
// priority_queue::push(), priority_queue::pop(),
// priority_queue::empty(), priority_queue::top(), queue::size()
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <functional>
void main(void)
{
int size_q;
INTPRQUE q;
CHPRQUE p;
{
cout << q.top() << endl;
q.pop();
}
}
Program Output:
42
size of q is:4
42
49
100
201
m
size of p is:5
m
h
d
c
a
Required Header:
<queue>
Prototype:
queue::push();
queue::pop();
queue::empty();
queue::back();
queue::front();
queue::size();
Description:
The sample shows queue implementation using list and deque
containers.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: none
//
// <filename> : queue.cpp
//
// Functions:
//
// queue::push(), queue::pop(), queue::empty(), queue::back(),
// queue::front(),queue::size()
//
////////////////////////////////////////////////////////////////////
void main(void)
{
int size_q;
INTQUEUE q;
CHARQUEUE p;
q.push(100);
q.push(49);
q.push(201);
}
}
Program Output:
201
size of q is:4
42
100
49
201
horse
size of p is:5
cat
ape
dog
mouse
horse
The sample code below illustrates how to use the random_shuffle STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The random_shuffle algorithm shuffles the elements of a sequence
[first..last) in a random order. The non-predicate version uses an
internal random-number generator to generate the indices of the
elements to swap. The non-predicate version of random_shuffle uses
operator= to perform swaps.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// random_shuffle.cpp : Illustrates how to use the random_shuffle
// function.
//
// Functions:
//
// random_shuffle : Shuffle the elements in a random order.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 70 30 10 69 96 100 }
Numbers { 10 30 4 70 96 100 69 10 }
The sample code below illustrates how to use the predicate version
of the random_shuffle STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The random_shuffle algorithm shuffles the elements of a sequence
[first..last) in a random order. The predicate version uses the
pred function to generate the indices of the elements to swap. The
pred has to be a function object that takes a parameter n and
returns an integral random number in the range 0 - (n - 1). The
predicate version of random_shuffle uses operator= to perform
swaps.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// random_shuffle.cpp: Illustrates how to use the predicate version
// of the random_shuffle function.
//
// Functions:
//
// random_shuffle: Shuffle the elements in a random order.
//
// Rand: Given n, generates an integral random number in the
// in the range 0 - (n - 1).
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 70 30 10 69 96 100 }
Numbers { 10 30 4 70 96 100 69 10 }
The sample code below illustrates how to use the remove STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The remove algorithm removes all elements that match value from the
range (first, last). It returns an iterator equal to last - N,
where N = number of elements removed. The last N elements of the
range have undefined values. The size of the container remains the
same.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// remove.cpp : Illustrates how to use the remove function.
//
// Functions:
//
// remove - remove all elements from the sequence that match value
// begin - Returns an iterator that points to the first element in
// sequence.
// end - Returns an iterator that points one past the end of a seq
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
The sample code below illustrates how to use the remove_copy STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The remove_copy algorithm copies all elements from the range
(first, last) to the range starting at result, skipping any element
that matches value. It returns an iterator positioned immediately
after the last new element.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// remove_copy.cpp : Illustrates how to use the remove_copy function
//
// Functions:
//
// remove_copy - copy the elements of a sequence to another sequen
// eliminating any elements that match value.
// begin - Returns an iterator that points to the first element in
// sequence.
// end - Returns an iterator that points one past the end of a seq
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int MAX_ELEMENTS = 8 ;
Numbers { 10 20 10 15 12 7 9 10 }
The sample code below illustrates how to use the remove_copy_if STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The remove_copy_if algorithm copies all elements from the range
(first, last) to the range starting at result, skipping any element
that causes the predicate to return true. It returns an iterator
positioned immediately after the last new element.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// remove_copy_if.cpp : Illustrates how to use the remove_copy_if fu
//
// Functions:
//
// remove_copy_if - copy the elements of a sequence to another seq
// eliminating any elements that satisfy a predic
// bind2nd - Returns true for elements for which the condition is
// begin - Returns an iterator that points to the first element in
// sequence
// end - Returns an iterator that points one past the end of a seq
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int MAX_ELEMENTS = 8 ;
Numbers[2] = 10 ;
Numbers[3] = 15 ;
Numbers[4] = 12 ;
Numbers[5] = 25 ;
Numbers[6] = 30 ;
Numbers[7] = 10 ;
Numbers { 10 20 10 15 12 25 30 10 }
The sample code below illustrates how to use the remove_if STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The remove_if algorithm removes all elements from the range (first,
last) that cause the predicate to return true. It returns an
iterator equal to last - N, where N = number of elements removed.
The last N elements of the range have undefined values. The size of
the container remains the same.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// remove_if.cpp : Illustrates how to use the remove_if function.
//
// Functions:
//
// remove_if - remove all elements from the sequence that
// satisfies a predicate.
// bind2nd - Returns true for elements for which the condition is
// begin - Returns an iterator that points to the first element in
// sequence
// end - Returns an iterator that points one past the end of a seq
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
The sample code below illustrates how to use the replace STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The replace algorithm replaces all elements that match old_value
from the range [first, last) with new_value.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// replace.cpp : Illustrates how to use the replace function.
//
// Functions:
//
// replace - Replace all elements from the sequence that match va
// with another value.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
cout << "After calling replace, to replace all 10's with 35" <<
The sample code below illustrates how to use the replace_copy STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The replace_copy algorithm copies all elements from the range
[first, last) to a same-size range starting at result, replacing
all occurrences of old_value with new_value in the resulting
sequence. It returns an iterator positioned immediately after the
last new element in the resulting sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// replace_copy.cpp : Illustrates how to use the replace_copy functi
//
// Functions:
//
// replace_copy - Copy the elements of a sequence to another
// same-size sequence replacing any elements
// that match a value with another value.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int MAX_ELEMENTS = 8 ;
Numbers { 10 20 10 15 12 7 9 10 }
Required Header:
<algorithm>
Prototype:
Description:
The replace_copy_if algorithm copies all elements from the range
[first, last) to a same-size range starting at result, replacing
all occurrences that cause the predicate to return true with
new_value in the resulting sequence. It returns an iterator
positioned immediately after the last new element in the resulting
sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// replace_copy_if.cpp : Illustrates how to use the replace_copy_if
// function.
//
// Functions:
//
// replace_copy_if - Copy the elements of a sequence to another
// same-size sequence replacing any elements
// that satisfies a predicate, with another val
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int MAX_ELEMENTS = 8 ;
Numbers { 10 20 10 15 12 7 9 10 }
The sample code below illustrates how to use the replace_if STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The replace_if algorithm replaces all elements from the range
[first, last) that cause the predicate to return true with value.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// replace_if.cpp : Illustrates how to use the replace_if function.
//
// Functions:
//
// replace_if - Replace all elements from the sequence that
// satisfies a predicate with a specified value.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
The sample code below illustrates how to use the reverse STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The reverse algorithm reverses the order of the elements in the
range [first, last).
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// reverse.cpp : Illustrates how to use the reverse function.
//
// Functions:
//
// reverse - Reverse the items in a sequence.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
StrVector Tongue_Twister(VECTOR_SIZE) ;
Try this Tongue Twister: she sells sea shells by the sea shore
Now try the reversed Tongue Twister: shore sea the by shells sea sel
The sample code below illustrates how to use the reverse_copy STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The reverse_copy algorithm reverses the order of the elements in
the range [first, last) and copies the result into a sequence of
the same size starting at result. It returns an iterator positioned
immediately after the last new element in the resulting sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// reverse_copy.cpp : Illustrates how to use the reverse_copy functi
//
// Functions:
//
// reverse_copy - Reverse a sequence, copy the results to another
// same-sized sequence.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
StrVector Tongue_Twister(VECTOR_SIZE) ;
StrVector Reversed_Twister(VECTOR_SIZE) ;
Tongue_Twister[5] = "the";
Tongue_Twister[6] = "sea" ;
Tongue_Twister[7] = "shore" ;
Try this Tongue Twister: she sells sea shells by the sea shore
Now try the reversed Tongue Twister: shore sea the by shells sea sel
The sample code below illustrates how to use the rotate STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The rotate algorithm rotates the elements in the range [first,
last) to the right by N positions, where N = middle - first.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// rotate.cpp : Illustrates how to use the rotate function.
//
// Functions:
//
// rotate - Rotate the items in a sequence by n positions.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
StrVector Tongue_Twister(VECTOR_SIZE) ;
Try this Tongue Twister: she sells sea shells by the sea shore
Now try the rotated Tongue Twister: shells by the sea shore she sell
The sample code below illustrates how to use the rotate_copy STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The rotate_copy algorithm rotates the elements in the range [first,
last) to the right by N positions (where N = middle - first), and
copies the result into a sequence of the same size, starting at
result. It returns an iterator positioned immediately after the
last new element in the resulting sequence. Note that the
OutputIterator should be different from the sequence to be rotated.
If they are the same, the result will depend on the implementation.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// rotate_copy.cpp : Illustrates how to use the rotate_copy function
//
// Functions:
//
// rotate_copy - Rotate a sequence by n positions, copy the
// results to another same sized sequence.
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
void main()
{
const int VECTOR_SIZE = 8 ;
StrVector Tongue_Twister(VECTOR_SIZE) ;
StrVector Rotated_Twister(VECTOR_SIZE) ;
Try this Tongue Twister: she sells sea shells by the sea shore
Now try the rotated Tongue Twister: shells by the sea shore she sell
Required Header:
<set>
Prototype:
Description:
The lower_bound function returns an iterator to the earliest
element in the controlled sequence that has a key that does not
match the value passed to the lower_bound function. The upper_bound
function returns an iterator to the earliest element in the
controlled sequence that has a key matching the value passed to the
upper_bound function. If no such element exists, the function
returns end(). In both cases, the function set::key_comp()(key, x)
is used to determine if the keys match. The equal_range function
returns a pair value, where .first is the result of the lower_bound
function, and .second is the result of the upper_bound function.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetBoundRange.cpp:
// Illustrates how to use the lower_bound function to get an
// iterator to the earliest element in the controlled sequence
// that has a key that does not match the value passed to the
// function. It also illustrates how to use the upper_bound
// function to get an iterator to the earliest element in the
// controlled sequence that has a key that matches the value
// passed to the function. The last thing it illustrates is
// how to use the equal_range function to get a pair value that
// contains the lower_bound and upper_bound results of the key.
//
// Functions:
//
// lower_bound Returns an iterator whose value does not match th
// key passed to the function, or end() if no such
// element exists.
// upper_bound Returns an iterator whose value matches the key
// passed to the function, or end() if no such eleme
// exists.
// equal_range Returns a pair of (lower_bound,upper_bound).
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void main() {
SET_INT s1;
SET_INT::iterator i;
cout << "s1.insert(5)" << endl;
s1.insert(5);
cout << "s1.insert(10)" << endl;
s1.insert(10);
cout << "s1.insert(15)" << endl;
s1.insert(15);
cout << "s1.insert(20)" << endl;
s1.insert(20);
cout << "s1.insert(25)" << endl;
s1.insert(25);
cout << "s1 has " << *i << " in its set." << endl;
s1.insert(5)
s1.insert(10)
s1.insert(15)
s1.insert(20)
s1.insert(25)
s1 -- starting at s1.low
s1 has 15 in its set.
s1 has 20 in its set.
s1 has 25 in its set.
s1 -- starting at s1.low
s1 has 15 in its set.
s1 has 20 in its set.
s1 has 25 in its set.
s1 -- starting at s1.upp
s1 has 15 in its set.
s1 has 20 in its set.
s1 has 25 in its set.
s1 -- starting at s1.upp
s1 has 20 in its set.
s1 has 25 in its set.
s1 -- s1.equal_range(12)
s1 -- s1.equal_range(15)
s1 has 15 in its set.
The sample code below illustrates how to use the set::key_comp and
set::value_comp STL functions in Visual C++.
Required Header:
<set>
Prototype:
Description:
The key_comp function returns the stored function object that
determines the order of elements in the controlled sequence. The
value_comp function returns the same function that key_comp
returns.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetComp.cpp:
// Illustrates how to use the key_comp function to obtain a
// function pointer that is the stored function object that
// determines the order of elements in the controlled sequence.
// It also illustrates how to use the value_comp function to
// obtain a function pointer that is the stored function object
// that determines the order of the elements in the controlled
// sequence (same as key_comp result).
//
// Functions:
//
// key_comp Returns a function pointer to the function that
// determines the order of elements in the controlle
// sequence.
// value_comp Returns a function pointer to the function that
// determines the order of elements in the controlle
// sequence (same as key_comp).
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void truefalse(int x)
{
cout << (x?"True":"False") << endl;
}
void main() {
SET_INT s1;
The sample code below illustrates how to use the set::count STL
function in Visual C++.
Required Header:
<set>
Prototype:
// Function 1:
size_type count(const _K& _Kv) const;
}
Description:
The count function is used to determine the number of elements in
the controlled sequence that have a particular key.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetCount.cpp:
// Illustrates how to use the count function to determine how
// many elements have a particular key.
//
// Functions:
//
// count Returns the number of elements in the controlled
// sequence that have a particular key.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void truefalse(int x)
{
cout << (x?"True":"False") << endl;
}
void main() {
SET_INT s1;
SET_INT::_Pairib pib;
cout << "s1.insert(5)" << endl;
pib=s1.insert(5);
cout << "Inserted element: ";
truefalse(pib.second); // True
s1.insert(5)
Inserted element: True
s1.insert(5)
Inserted element: False
s1.insert(8)
s1.insert(12)
s1.count(5) returned 1
s1.count(9) returned 0
The sample code below illustrates how to use the set::empty and
set::clear STL functions in Visual C++.
Required Header:
<set>
Prototype:
Description:
The empty function returns true when there are no elements in the
controlled sequence. By calling erase(begin,end), the clear
function removes all elements in the controlled sequence. For more
information on the erase function, see set::erase.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetEmpty&Clear.cpp:
// Illustrates how to use the empty function to determine if
// there are elements in the controlled sequence. It also
// illustrates how to use the clear function to remove all
// elements from the controlled sequence.
//
// Functions:
//
// empty Returns true if there are no elements in the
// controlled sequence.
// clear Removes all elements from the controlled sequence
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void truefalse(int x)
{
cout << (x?"True":"False") << endl;
}
void main() {
SET_INT s1;
The sample code below illustrates how to use the set::find STL
function in Visual C++.
Required Header:
<set>
Prototype:
Description:
The find function is used to locate an element in a controlled
sequence. It returns an iterator to the first element in the
controlled sequence whose sort key matches its parameter. If no
such element exists, the returned iterator equals end().
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetFind.cpp:
// Illustrates how to use the find function to get an iterator
// that points to the first element in the controlled sequence
// that has a particular sort key.
//
// Functions:
//
// find Returns an iterator that points to the first elem
// in the controlled sequence that has the same sort
// as the value passed to the find function. If no s
// element exists, the iterator equals end().
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void truefalse(int x)
{
cout << (x?"True":"False") << endl;
}
void main() {
SET_INT s1;
cout << "s1.insert(5)" << endl;
s1.insert(5);
cout << "s1.insert(8)" << endl;
s1.insert(8);
cout << "s1.insert(12)" << endl;
s1.insert(12);
SET_INT::iterator it;
cout << "it=find(8)" << endl;
it=s1.find(8);
cout << "it!=s1.end() returned ";
truefalse(it!=s1.end()); // True
s1.insert(5)
s1.insert(8)
s1.insert(12)
it=find(8)
it!=s1.end() returned True
it=find(6)
it!=s1.end() returned False
The sample code below illustrates how to use the set::max_size STL
function in Visual C++.
Required Header:
<set>
Prototype:
class set
{
public:
// Function 1:
size_type max_size() const;
}
Description:
The max_size function is used to determine the maximum number of
elements the controlled sequence can contain.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetMax_size.cpp:
// Illustrates how to use the max_size function to determine ho
// many elements the controlled sequence can contain.
//
// Functions:
//
// max_size Returns the maximum number of elements the contro
// sequence can contain.
//
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
#include <assert.h>
void main() {
SET_INT s1;
The sample code below illustrates how to use the set::rbegin and
set::rend STL functions in Visual C++.
Required Header:
<set>
Prototype:
Description:
The rbegin function returns a reverse bidirectional iterator that
points just beyond the end of the controlled sequence. The rend
function returns a reverse bidirectional iterator that points at
the first element of the sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetRbeginRend.cpp:
// Illustrates how to use the rbegin function to get a reverse
// bidirectional iterator that points just beyond the end of
// the controlled sequence. It also illustrates how to use
// the rend function to get a reverse bidirectional iterator
// that points at the first element of the sequence.
//
// Functions:
//
// rbegin Returns a reverse bidirectional iterator that poin
// just beyond the end of the controlled sequence.
// rend Returns a reverse bidirectional iterator that poin
// at the first element of the sequence.
//
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void main() {
SET_INT s1;
SET_INT::reverse_iterator i;
cout << "s1.insert(5)" << endl;
s1.insert(5);
cout << "s1.insert(10)" << endl;
s1.insert(10);
cout << "s1.insert(15)" << endl;
s1.insert(15);
cout << "s1.insert(20)" << endl;
s1.insert(20);
// displays: 20,15,10,5
for (i=s1.rbegin();i!=s1.rend();i++)
cout << "s1 has " << *i << " in its set." << endl;
}
s1.insert(5)
s1.insert(10)
s1.insert(15)
s1.insert(20)
s1 has 20 in its set.
s1 has 15 in its set.
s1 has 10 in its set.
s1 has 5 in its set.
The sample code below illustrates how to use the set::size STL
function in Visual C++.
Required Header:
<set>
Prototype:
Description:
The size function is used to determine the number of elements in
the controlled sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetSize.cpp:
// Illustrates how to use the size function to determine how
// many elements are in the controlled sequence.
//
// Functions:
//
// size Returns the number of elements in the controlled
// sequence.
//
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void main() {
SET_INT s1;
s1.size() returned 0
s1.insert(5)
s1.insert(8)
s1.insert(12)
s1.size() returned 3
The sample code below illustrates how to use the set::(swap, begin,
end) STL functions in Visual C++.
Required Header:
<set>
Prototype:
Description:
The swap function swaps the two controlled sequences. The begin
function returns a bidirectional iterator that points at the first
element of the sequence. The end function returns a bidirectional
iterator that points just beyond the end of the sequence.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// SetSwapBeginEnd.cpp:
// Illustrates how to use the swap function to exchange the two
// controlled sequences. It also illustrates how to use the
// begin function to get a bidirectional iterator that points a
// the first element of the controlled sequence. Finally, it
// illustrates how to use the end function to get a bidirection
// iterator that points just beyond the end of the controlled
// sequence.
//
// Functions:
//
#pragma warning(disable:4786)
#include <set>
#include <iostream>
void main() {
SET_INT s1;
SET_INT s2;
SET_INT::iterator i;
cout << "s1.insert(5)" << endl;
s1.insert(5);
cout << "s1.insert(10)" << endl;
s1.insert(10);
cout << "s1.insert(15)" << endl;
s1.insert(15);
cout << "s2.insert(2)" << endl;
s2.insert(2);
cout << "s2.insert(4)" << endl;
s2.insert(4);
// Displays: 2,4
for (i=s1.begin();i!=s1.end();i++)
cout << "s1 has " << *i << " in its set." << endl;
// Displays: 5,10,15
for (i=s2.begin();i!=s2.end();i++)
cout << "s2 has " << *i << " in its set." << endl;
// Displays: 5,10,15
for (i=s1.begin();i!=s1.end();i++)
cout << "s1 has " << *i << " in its set." << endl;
// Displays: 2,4
for (i=s2.begin();i!=s2.end();i++)
cout << "s2 has " << *i << " in its set." << endl;
}
s1.insert(5)
s1.insert(10)
s1.insert(15)
s2.insert(2)
s2.insert(4)
swap(s1,s2)
s1 has 2 in its set.
s1 has 4 in its set.
s2 has 5 in its set.
s2 has 10 in its set.
s2 has 15 in its set.
s1.swap(s2)
s1 has 5 in its set.
s1 has 10 in its set.
s1 has 15 in its set.
s2 has 2 in its set.
s2 has 4 in its set.
The sample code below illustrates how to use the sqrt and pow STL
functions in Visual C++.
Required Header:
<valarray>
Prototype:
// sqrt
template<class T>
inline valarray<T> sqrt(const valarray<T>& x);
// pow
template<class T>
inline valarray<T> pow(const valarray<T>& x, const valarray<T>&
template<class T>
inline valarray<T> pow(const valarray<T> x, const T& y);
template<class T>
inline valarray<T> pow(const T& x, const valarray<T>& y);
Description:
This article illustrates the use of STL sqrt() and pow() functions
through sample code. sqrt() returns an object of class valarray<T>,
each of whose elements at index I is the square root of x[I]. pow()
has three template functions. The first template function returns
an object of class valarray<T>, each of whose elements at index I
is x[I] raised to the power of y[I]. The second template function
stores in element I x[I] raised to the power of y. The third
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// main.cpp : Illustrates the use of STL sqrt() and pow() functions.
//
// Functions:
//
// sqrt, pow
////////////////////////////////////////////////////////////////////
void main()
{
// Set val_array to contain values 1, 4, 9 for the following tes
valarray<double> val_array(ARRAY_SIZE);
valarray<double> rvalue_array;
// -------------------------------------------------------------
// sqrt() - display the content of rvalue_array
// -------------------------------------------------------------
// -------------------------------------------------------------
// pow() - display the content of rvalue_array
// -------------------------------------------------------------
Size of val_array = 3
The values in val_array:
1 4 9
Size of rev_valarray = 3
The values in rev_valarray:
9 4 1
1 2 3
Required Header:
<stack>
Prototype:
Description:
The stack::operator== function returns true if both stacks have
equal elements arranged in the same sequence. The stack::operator==
function always returns false if the two stacks are of different
size.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StackEqual.cpp : Illustrates how to use the stack::operator==
// function to determine if two stacks are equal.
//
// Functions:
//
// operator== : Returns true if both stacks are the same.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <stack>
#include <iostream>
void main()
{
STACK_DOUBLE stack1,stack2;
// Add item 3.0 to Stack1. Current Stack1 contains items 3.0 (top
// 4.0 (bottom).
cout << "stack1.push(3.0) s1=[3.0 4.0]" << endl;
stack1.push(3.0);
// Add item 6.0 to Stack2. Current Stack2 contains items 6.0 (top
// 4.0 (bottom)
cout << "stack2.push(6.0) s2=[6.0 4.0]" << endl;
stack2.push(6.0);
// Delete the top item from Stack2. Current Stack2 contains items
// 6.0 (top) and 4.0 (bottom).
cout << "stack2.pop() s2=[6.0 4.0]" << endl;
stack2.pop();
// Add item 3.0 to Stack2. Current Stack2 contains item 3.0 (top)
// 4.0 (bottom).
cout << "stack2.push(3.0) s2=[3.0 4.0]" << endl;
stack2.push(3.0);
// Delete the top item from Stack2. Current Stack2 contains 4.0.
cout << "stack2.pop() s2=[4.0]" << endl;
stack2.pop();
stack1.push(4.0) s1=[4.0]
stack1.push(3.0) s1=[3.0 4.0]
stack2.push(4.0) s2=[4.0]
stack1==stack2 is False
stack2.pop() s2=[4.0]
stack2.pop() s2=[]
stack2.push(8.0) s2=[8.0]
stack1==stack2 is False
Required Header:
<stack>
Prototype:
Description:
The stack::operator< function returns true if the stack on the left
side of the operator is less than the stack on the right side. The
following steps are used to determine if one stack is less than
another stack: 1. Compare the bottom-most (very first element
pushed onto the stack). 2. If the elements are different, the stack
with the smaller element is less than the stack with the greater
element. Go to Step 5. 3. If the elements are the same and there
are more elements, move to the next element in the stack and go
back to step 2. 4. If all the elements in the stacks are processed
at this point, the stacks are equal. 5. Done.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StackLessThan.cpp : Illustrates how to use the stack::operator<
// function to determine if one stack is less th
// another stack.
//
// Functions:
//
// operator< : Returns true if the stack is smaller than the sta
// passed as the operand.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <stack>
#include <iostream>
void main()
{
STACK_DOUBLE stack1,stack2;
stack1.push(4.0) s1=[4.0]
stack1.push(3.0) s1=[3.0 4.0]
stack2.push(4.0) s2=[4.0]
stack1<stack2 is False
stack2.pop() s2=[4.0]
stack2.pop() s2=[]
stack2.push(8.0) s2=[8.0]
stack1<stack2 is True
The sample code below illustrates how to use the stack::size STL
function in Visual C++.
Required Header:
<stack>
Prototype:
Description:
The stack::size function returns the number of elements in the
stack. It is okay to call this function with an empty stack; it
will return a value of 0.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StackSize.cpp : Illustrates how to use the size function to deter
// the number of elements on the stack.
//
// Functions:
//
// size : returns the number of elements in the stack.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <stack>
#include <string>
#include <iostream>
void main()
{
STACK_STRING stack1;
// Pop "Hello".
cout << "stack1.pop()" << endl;
stack1.pop();
stack1.size() equals 0
stack1.push('Hello')
stack1.push('This is the second element')
stack1.size() equals 2
stack1.push('Third element')
stack1.size() equals 3
stack1.pop()
stack1.pop()
stack1.size() equals 1
stack1.pop()
stack1.size() equals 0
The sample code below illustrates how to use the stack::top and
stack::empty STL functions in Visual C++.
Required Header:
<stack>
Prototype:
Description:
The top function returns the topmost element of the stack. You
should ensure that there are one or more elements on the stack
before calling the top function. The first version of the top
function returns a reference to the element of the top of the
stack, allowing you to modify the value. The second function
returns a constant reference, ensuring that you don't accidentally
modify the stack. The empty function returns true if there are no
elements in the stack. If there are one or more elements, the
function will return false. You should use the empty function to
verify that there are elements left on the stack before calling the
top function.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StackTop&Empty.cpp : Illustrates how to use the top function to
// retrieve the last element of the controlled
// sequence. It also illustrates how to use the
// empty function to loop though the stack.
// Functions:
//
// top : returns the top element of the stack.
// empty : returns true if the stack has 0 elements.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <stack>
#include <iostream>
void main()
{
STACK_INT stack1;
if (!stack1.empty()) // Function 3
cout << "stack1.top() returned " <<
stack1.top() << endl; // Function 1
if (!stack1.empty()) // Function 3
cout << "stack1.top() returned " <<
stack1.top() << endl; // Function 1
if (!stack1.empty()) // Function 3
cout << "stack1.top() returned " <<
stack1.top() << endl; // Function 1
Required Header:
<string>
Prototype:
Description:
The getline function creates a string containing all of the
characters from the input stream until one of the following
situations occurs: - End of file. - The delimiter is encountered. -
is.max_str() elements have been extracted.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// Getline.cpp : Illustrates how to use the getline function to read
// line of text from the keyboard.
//
// Functions:
//
// getline Returns a string from the input stream.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void main()
{
string s1;
cout << "Enter a sentence (use <space> as the delimiter):";
getline(cin,s1, ' ');
cout << "You entered: " << s1;
}
Required Header:
<string>
Prototype:
Function 1:
template<class _E, class _TYPE, class _A> inline
bool operator==(const basic_string<_E, _TYPE, _A>& LString,
const _E *RCharArray);
Function 2:
template<class _E, class _TYPE, class _A> inline
bool operator==(const _E * LCharArray,
const basic_string<_E, _TYPE, _A>& RString);
Function 3:
template<class _E, class _TYPE, class _A> inline
bool operator==(const basic_string<_E, _TYPE, _A>& LString,
const basic_string<_E, _TYPE, _A>& RString);
Description:
There are three versions of the string::operator== function. The
first two functions compare a null-terminated character array
against a basic_string. They perform this operation by using the
basic_string's string::compare function and returning true if the
compare function returns a 0 value. The third function compares two
basic_string variables, using the string::compare function of the
first basic_string variable. For more information on the compare
function, see the string::compare function. Note that this operator
does not work with NULL pointer for the character array. You will
need to make sure that the character array is not NULL before you
pass it to the operator.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StringEqual.cpp: Illustrates how to use the operator== to test fo
// equality of a basic_string variable and a
// null-terminated string. It also illustrates how
// use the operator== to test for equality of two
// basic_string variables.
//
// Functions:
//
// operator== returns true if the basic_string and the null-
// terminated string are equal.
// operator== returns true if both basic_strings are equal.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void trueFalse(int x)
{
cout << (x? "True": "False") << endl;
}
void main()
{
string S1="ABC";
string S2="ABC";
string S3="DEF";
string S4; //This specifies an empty initial-controlled sequence.
char CP1[]="abc";
char CP2[]="DEF";
char *CP3 = NULL;
S1 is ABC
S2 is ABC
S3 is DEF
S4 is
CP1 is abc
CP2 is DEF
S1==CP1 returned False
S1==CP2 returned False
CP1==S1 returned False
CP2==S1 returned False
S1==S2 returned True
S1==S3 returned False
S1==S4 returned False
Required Header:
<string>
Prototype:
Function 1:
template<class _E, class _TYPE, class _A> inline
bool operator>(const basic_string<_E, _TYPE, _A>& LString,
const _E *RCharArray);
Function 2:
template<class _E, class _TYPE, class _A> inline
bool operator>(const _E *LCharArray,
const basic_string<_E, _TYPE, _A>& RString);
Description:
There are two versions of the string::operator> function. Both
versions are used to compare a null-terminated character array to a
basic_string. They perform this operation by returning the result
of (RString<LCharArray or RCharArray<LString). For more information
on this comparison, see the string::operator< function. Note that
this operator does not work with NULL pointer for the character
array. You will need to make sure that the character array is not
NULL before you pass it to the operator.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StringGreaterThan.cpp : Illustrates how to use the operator> to
// compare a basic_string variable to a
// null-terminated string.
//
// Functions:
//
// operator> Returns true if the second parameter is less than
// the first.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void trueFalse(int x)
{
cout << (x? "True": "False") << endl;
void main()
{
string S1="ABC";
char CP1[]="ABC";
char CP2[]="DEF";
char CP3[]="ABCD";
char CP4[]="abc";
S1 is ABC
CP1 is ABC
CP2 is DEF
CP3 is ABCD
CP4 is abc
S1>CP1 returned False
S1>CP2 returned False
S1>CP4 returned False
CP1>S1 returned False
CP2>S1 returned True
CP3>S1 returned True
Required Header:
<string>
Prototype:
Function 1:
template<class _E, class _TYPE, class _A> inline
bool operator>=(const basic_string<_E, _TYPE, _A>& _L,
const _E *_R);
Function 2:
template<class _E, class _TYPE, class _A> inline
bool operator>=(const _E * _L,
const basic_string<_E, _TYPE, _A>& _R);
Description:
There are two versions of the string::operator>= function. Both
versions are used to compare a null-terminated character array
against a basic_string. They perform this operation by negating the
result of (_L < _R). For more information on this comparison,
please see the string::operator< function.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: none
//
// StringGreaterEqual.cpp:
// Illustrates how to use the operator>= to compare a
// basic_string variable and a null-terminated string.
//
// Functions:
//
// operator>= Returns true if the first parameter is not less
// the second.
//
// Written by Derek Jamison
// of Microsoft AnswerPoint Support,
// Copyright (c) 1996 Microsoft Corporation. All rights reserved.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void truefalse(int x)
{
cout << (x?"True":"False") << endl;
}
void main()
{
string S1="ABC";
char CP1[4]="ABC";
char CP2[4]="DEF";
S1 is ABC
CP1 is ABC
CP2 is DEF
S1>=CP1 returned True
S1>=CP2 returned False
CP1>=S1 returned True
CP2>=S1 returned True
Required Header:
<string>
Prototype:
Description:
The operator>> is used to populate a string with the contents of an
input stream.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StringExtract.cpp : Illustrates how to use the operator>> to extr
// a string from an input stream, populating a s
// variable with the contents.
//
// Functions:
//
// operator>> Extracts a string from an input stream.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void main()
{
string s1;
cout << "Enter a word: ";
cin >> s1;
cout << endl << "You entered: " << s1;
}
Required Header:
<string>
Prototype:
Function 1:
template<class _E, class _TYPE, class _A> inline
bool operator<(const basic_string<_E, _TYPE, _A>& LString,
const _E *RCharArray);
Function 2:
template<class _E, class _TYPE, class _A> inline
bool operator<(const _E *LCharArray,
const basic_string<_E, _TYPE, _A>& RString);
Function 3:
template<class _E, class _TYPE, class _A> inline
bool operator<(const basic_string<_E, _TYPE, _A>& LString,
const basic_string<_E, _TYPE, _A>& RString);
Description:
There are three versions of the string::operator< function. Two of
the functions compare a null-terminated character array against a
basic_string. They perform this operation by using the
basic_string's string::compare function and returning a value based
on the results of the compare function. The third function compares
two basic_string variables, using the string::compare function of
the first basic_string variable. For more information on the
compare function, please see the string::compare function. Note
that this operator does not work with NULL pointer for the
character array. You will need to make sure that the character
array is not NULL before you pass it to the operator.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StringLessThan.cpp : Illustrates how to use the operator< to comp
// a basic_string variable and a null-terminate
// string. It also illustrates how to use the
// operator< to compare two basic_string variab
//
// Functions:
//
// operator< Returns true if the first parameter is less than
// second.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void trueFalse(int x)
{
cout << (x? "True": "False") << endl;
}
void main()
{
string S1="ABC";
string S2="ABC";
string S3="DEF";
string S4="abc";
char CP1[]="ABC";
char CP2[]="DEF";
char CP3[]="ABCD";
S1 is ABC
S2 is ABC
S3 is DEF
S4 is abc
CP1 is ABC
CP2 is DEF
CP3 is ABCD
S1<CP1 returned False
S1<CP2 returned True
CP1<S1 returned False
CP2<S1 returned False
S1<S2 returned False
Required Header:
<string>
Prototype:
Function 1:
template<class _E, class _TYPE, class _A> inline
bool operator<=(const basic_string<_E, _TYPE, _A>& LString,
const _E *RCharArray);
Function 2:
template<class _E, class _TYPE, class _A> inline
bool operator<=(const _E * LCharArray,
const basic_string<_E, _TYPE, _A>& RString);
Description:
There are two versions of the string::operator<= function. Both
versions are used to compare a null-terminated character array to a
basic_string. They perform this operation by negating the result of
(RString<LCharArray or RCharArray<LString). For more information on
this comparison, please see the string::operator< function. Note
that this operator does not work with NULL pointer for the
character array. You will need to make sure that the character
array is not NULL before you pass it to the operator.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StringLessEqual.cpp : Illustrates how to use the operator<= to co
// a basic_string variable to a null-terminate
// string.
//
// Functions:
//
// operator<= Returns true if the second parameter is not less
// than the first.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void trueFalse(int x)
{
cout << (x? "True": "False") << endl;
}
void main()
{
string S1="DEF";
char CP1[]="ABC";
char CP2[]="DEF";
char CP3[]="DEFG";
char CP4[]="def";
S1 is DEF
CP1 is ABC
CP2 is DEF
CP3 is DEFG
CP4 is def
S1<=CP1 returned False
S1<=CP2 returned True
S1<=CP3 returned True
CP1<=S1 returned True
CP2<=S1 returned True
CP4<=S1 returned False
Required Header:
<string>
Prototype:
Description:
The operator<< is used to insert a string into an output stream.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StringInsertion.cpp : Illustrates how to use the insertion operat
// (operator<<) to insert a string into an out
// stream.
//
// Functions:
//
// operator<< Inserts a string into an output stream.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void main()
{
string msg="Hello! This is the insertion operator.";
cout << msg << endl;
}
Required Header:
<string>
Prototype:
Function 1:
template<class _E, class _TYPE, class _A> inline
basic_string<_E, _TYPE, _A>
operator+(const basic_string<_E, _TYPE, _A>& LString,
const _E *RCharArray);
Function 2:
template<class _E, class _TYPE, class _A> inline
basic_string<_E, _TYPE, _A>
operator+(const _E *LCharArray,
const basic_string<_E, _TYPE, _A>& RString);
Function 3:
template<class _E, class _TYPE, class _A> inline
basic_string<_E, _TYPE, _A>
operator+(const basic_string<_E, _TYPE, _A>& LString,
const _E RChar);
Function 4:
template<class _E, class _TYPE, class _A> inline
basic_string<_E, _TYPE, _A>
operator+(const _E LChar,
const basic_string<_E, _TYPE, _A>& RString);
Function 5:
template<class _E, class _TYPE, class _A> inline
basic_string<_E, _TYPE, _A>
operator+(const basic_string<_E, _TYPE, _A>& LString,
const basic_string<_E, _TYPE, _A>& RString);
Description:
There are five versions of the string::operator+ function. Two
functions are used to concatenate a null-terminated character array
and a basic_string. Two functions are used to concatenate a
character and a basic_string. The last function is used to
concatenate two basic_string variables.
Sample Code:
////////////////////////////////////////////////////////////////////
//
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void main()
{
string result;
string S1="ABC";
string S2="DEF";
char CP1[]="GHI";
char C='J';
S1 is ABC
S2 is DEF
CP1 is GHI
C is J
S1+CP1 is ABCGHI
CP1+S1 is GHIABC
S1+S2 is ABCDEF
S1+C is ABCJ
C+S1 is JABC
Required Header:
<string>
Prototype:
Function 1:
template<class _E, class _TYPE, class _A> inline
bool operator!=(const basic_string<_E, _TYPE, _A>& LString,
const _E *RCharArray);
Function 2:
template<class _E, class _TYPE, class _A> inline
bool operator!=(const _E *LCharArray,
const basic_string<_E, _TYPE, _A>& RString);
Description:
There are two versions of the string::operator!= function. Both
versions are used to compare a null-terminated character array
against a basic_string. They perform this operation by negating the
result of (LString==RCharArray) or (LCharArray==RString). For more
information on this comparison, please see the string::operator==
function. Notice that this operator does not work with NULL pointer
for the character array. You will need to make sure that the
character array is not NULL before you pass it to the operator.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// StringNotEqual.cpp : Illustrates how to use the operator!= to tes
// non-equality of a basic_string variable and
// null-terminated string.
//
// Functions:
//
// operator!= Returns true if the basic_string and the null-
// terminated string are not equal.
////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
void trueFalse(int x)
{
cout << (x? "True": "False") << endl;
}
void main()
{
string S1="ABC";
char CP1[]="ABC";
char CP2[]="DEF";
char CP3[]="abc";
S1 is ABC
CP1 is ABC
CP2 is DEF
CP3 is abc
S1!=CP1 returned False
S1!=CP2 returned True
S1!=CP3 returned True
CP1!=S1 returned False
CP2!=S1 returned True
CP3!=S1 returned True
Required Header:
<valarray>
Prototype:
// acos
template<class T>
inline valarray<T> acos(const valarray<T>& x);
// asin
template<class T>
inline valarray<T> asin(const valarray<T>& x);
// atan
template<class T>
inline valarray<T> atan(const valarray<T>& x);
// atan2
template<class T>
inline valarray<T> atan2(const valarray<T>& x, const valarray<T
template<class T>
inline valarray<T> atan2(const valarray<T> x, const T& y);
template<class T>
inline valarray<T> atan2(const T& x, const valarray<T>& y);
// cos
template<class T>
inline valarray<T> cos(const valarray<T>& x);
// cosh
template<class T>
inline valarray<T> cosh(const valarray<T>& x);
// sin
template<class T>
inline valarray<T> sin(const valarray<T>& x);
// sinh
template<class T>
inline valarray<T> sinh(const valarray<T>& x);
// tan
template<class T>
inline valarray<T> tan(const valarray<T>& x);
// tanh
template<class T>
inline valarray<T> tanh(const valarray<T>& x);
Description:
This article illustrates the use of STL trigonometry functions
through sample code.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// main.cpp : Illustrates the use of STL trigonometry functions.
//
// Functions:
//
// acos, asin, atan, atan2, cos, cosh, sin, sinh, tan, tanh
////////////////////////////////////////////////////////////////////
void main()
{
// Initialize val_array to values -1, 0 and 1.
valarray<double> val_array(ARRAY_SIZE);
for (int i = 0; i < ARRAY_SIZE; i++)
val_array[i] = i - 1;
// -------------------------------------------------------------
// acos() - display the result of rvalue_array
// -------------------------------------------------------------
rvalue_array = acos(val_array);
cout << "The result after calling acos():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// asin() - display the result of rvalue_array
// -------------------------------------------------------------
rvalue_array = asin(val_array);
cout << "The result after calling asin():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// atan() - display the result of rvalue_array
// -------------------------------------------------------------
rvalue_array = atan(val_array);
cout << "The result after calling atan():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// atan2() - display the result of rvalue_array
// -------------------------------------------------------------
// x / y[I].
rvalue_array = atan2(3.1416, val_array);
cout << "The result after calling atan2(3.1416, val_array):" <<
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// cos() - display the result of rvalue_array
// -------------------------------------------------------------
rvalue_array = cos(val_array);
cout << "The result after calling cos():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// cosh() - display the result of rvalue_array
// -------------------------------------------------------------
rvalue_array = cosh(val_array);
cout << "The result after calling cosh():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// sin() - display the result of val_array
// -------------------------------------------------------------
rvalue_array = sin(val_array);
cout << "The result after calling sin():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// sinh() - display the result of val_array
// -------------------------------------------------------------
rvalue_array = sinh(val_array);
cout << "The result after calling sinh():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// tan() - display the result of val_array
// -------------------------------------------------------------
rvalue_array = tan(val_array);
cout << "The result after calling tan():" << endl;
for (i = 0; i < ARRAY_SIZE; i++)
cout << rvalue_array[i] << " ";
cout << endl << endl;
// -------------------------------------------------------------
// tanh() - display the result of val_array
// -------------------------------------------------------------
rvalue_array = tanh(val_array);
cout << "The result after calling tanh():" << endl;
Size of val_array = 3
The values in val_array:
-1 0 1
Size of rev_valarray = 3
The values in rev_valarray:
1 0 -1
Required Header:
< functional >
Prototype:
Description:
unary_function is used as a base class to better define operator
functions in the following format: result_type classname::operatorX
(argument_type).
Sample Code:
////////////////////////////////////////////
//
// Compile options needed: none
//
// Structure used:
// unary_function<int, float> - allows us
// to write operator functions accepting an
// integer and returning floats.
////////////////////////////////////////////
#include <functional>
#include <iostream>
unary_test::result_type unary_test::operator*(unary_test::argument_t
{
value*=x;
cout << "New value after * is " << value << endl ;
return value;
}
unary_test::result_type unary_test::operator-(unary_test::argument_t
{
value-+(float)x;
cout << "New value after minus is " << value << endl ;
return value;
}
void main(void)
{
unary_test item;
unary_test item2(18.0);
Begin
New value after * is 20.000000
New value after minus is 18.000000
The sample code below illustrates how to use the upper_bound STL
function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The upper_bound algorithm returns the last location in the sequence
that value can be inserted such that the order of the sequence is
maintained. upper_bound returns an iterator positioned at the
location that value can be inserted in the range [first..last), or
returns last if no such position exists. upper_bound assumes the
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// upper_bound.cpp : Illustrates how to use the upper_bound
// function.
//
// Functions:
//
// upper_bound : Return the upper bound within a range.
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the predicate version
of the upper_bound STL function in Visual C++.
Required Header:
<algorithm>
Prototype:
Description:
The upper_bound algorithm returns the last location in the sequence
that value can be inserted such that the order of the sequence
[first..last) is maintained. upper_bound returns an iterator
positioned at the location that value can be inserted in the range
[first..last), or returns last if no such position exists. This
version assumes the range [first..last) is sorted sequentially
using the compare function.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
void main()
{
const int VECTOR_SIZE = 8 ;
IntVector Numbers(VECTOR_SIZE) ;
Numbers { 4 10 10 30 69 70 96 100 }
The sample code below illustrates how to use the vector class
operator== STL function in Visual C++.
Required Header:
<vector>
Prototype:
Description:
The sample declares three empty vectors, of a user-defined class
called ID, each of which contains a Name string member and a Score
integer member. It creates three vectors of IDs, then compares
vectors using the operator== as defined for ID.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// Opequal.cpp : Illustrates how to define the operator== to comp
// vectors.
//
// Functions:
//
// vector::operator== - Vector equality comparison.
// vector::push_back - Appends (inserts) an element to the end of
// vector, allocating memory for it if necess
//
////////////////////////////////////////////////////////////////////
// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disab
#pragma warning(disable:4786)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
// The ID class is used for team scoring. It holds each player's nam
// and score.
class ID
{
public:
string Name;
int Score;
void main()
{
// Declare 3 dynamically allocated vectors of names.
NAMEVECTOR Vector1, Vector2, Vector3;
Vector1 != Vector2
Vector1 == Vector3
Required Header:
<vector>
Prototype:
Description:
The sample declares an empty vector of integers. It adds 10
integers to the vector, then displays the contents of the vector.
It deletes the sixth element by using erase, and then displays the
contents of the vector again. It deletes the rest of the elements
using a different form of erase, then displays the vector (now
empty) again. The ShowVector routine uses the empty function to
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// Empty.cpp -- Illustrates the vector::empty and vector::erase
// functions.
// Also demonstrates the vector::push_back function.
//
// Functions:
//
// vector::empty - Returns true if vector has no elements.
//
// vector::erase - Deletes elements from a vector (single & range
//
// vector::begin - Returns an iterator to start traversal of the
// vector.
//
// vector::end - Returns an iterator for the last element of the
// vector.
//
// vector::push_back - Appends (inserts) an element to the end of
// vector, allocating memory for it if necess
//
// vector::iterator - Traverses the vector.
//
////////////////////////////////////////////////////////////////////
// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disab
#pragma warning(disable:4786)
#include <iostream>
#include <vector>
void main()
{
// Dynamically allocated vector begins with 0 elements.
INTVECTOR theVector;
theVector [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
theVector [ 0, 1, 2, 3, 4, 6, 7, 8, 9 ]
theVector is empty.
The sample code below illustrates how to use the vector::front and
vector::back STL functions in Visual C++.
Required Header:
<vector>
Prototype:
Description:
The sample declares an empty vector of integers with the members
[100, 200, 300, 400]. It displays the first element of the vector
using vector::front to obtain it. It displays the last element of
the vector using vector::back to obtain it. It displays the number
of elements of the vector using vector::size. The sample erases the
last element of the vector using vector::end()-1, and then displays
the new last element using vector::back. It erases the first
element of the vector using vector::begin, and then displays the
new first element using vector::front. Finally, the sample displays
the number of elements remaining in the vector using vector::size.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// front.cpp: Illustrates the vector::front and vector::back meth
//
// Functions:
//
// vector::front - Returns reference to first element of vector.
//
// vector::back - Returns reference to last element of vector.
//
// vector::push_back - Appends (inserts) an element to the end of
// vector, allocating memory for it if necess
//
// vector::size - Returns number of elements in the vector.
//
// vector::begin - Returns an iterator to start traversal of the
//
// vector::end - Returns an iterator for the last element of the
//
// vector::erase - Deletes elements from a vector (single & range
//
////////////////////////////////////////////////////////////////////
// The debugger can't handle symbols more than 255 characters long.
#include <iostream>
#include <vector>
const ARRAY_SIZE = 4;
void main()
{
// Dynamically allocated vector begins with 0 elements.
INTVECTOR theVector;
// Delete the last element of the vector. Remember that the vect
// is 0-based, so theVector.end() actually points 1 element beyo
// the end.
theVector.erase(theVector.end() - 1);
cout << endl << "After erasing last element, new last element is
<< theVector.back() << endl;
cout << "After erasing first element, new first element is: "
<< theVector.front() << endl;
The sample code below illustrates how to use the the vector class
operator< STL function in Visual C++.
Required Header:
<vector>
Prototype:
Description:
The sample declares an empty vector of IDs, a user-defined type. It
initializes and adds four IDs to the vector in random order. It
sorts them using the operator< defined for ID and generates the
newly sorted vector. (Note that it sorts in order of Score, not
Name.)
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// Opless.cpp -- Illustrates the defining the < operator to sort
//
// Functions:
//
// operator< - Vector comparison operator.
//
// vector::begin - Returns an iterator to start traversal of the
//
// vector::end - Returns an iterator for the last element of the
//
// vector::iterator - Traverses the vector.
//
// vector::push_back - Appends (inserts) an element to the end of
// vector, allocating memory for it if necess
//
// sort algorithm - Sorts the vector.
//
////////////////////////////////////////////////////////////////////
// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disab
#pragma warning(disable:4786)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
// The ID class is used for team scoring. It holds each player's nam
// and score.
class ID
{
public:
string Name;
int Score;
ID() : Name(""), Score(0) {}
ID(string NewName, int NewScore) : Name(NewName), Score(NewScore
};
void main()
{
// Declare a dynamically allocated vector of IDs.
NAMEVECTOR theVector;
theIterator++)
cout << theIterator->Score << "\t"
<< theIterator->Name << endl;
cout << endl << endl;
}
Required Header:
<vector>
Prototype:
Description:
The sample declares an empty vector of integers. It adds three
integers to the vector, and then deletes one. Finally, it generates
the remaining elements in the vector.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// Pushpop.cpp: Illustrates how to use the push and pop member
// functions of the vector container.
//
// Functions:
//
// vector::push_back - Appends (inserts) an element to the end of
// vector, allocating memory for it if necess
//
// vector::pop_back - Erases the last element of the vector.
//
// vector::begin - Returns an iterator to start traversal of the
//
// vector::end - Returns an iterator for the last element of the
//
// vector::iterator - Traverses the vector.
//
////////////////////////////////////////////////////////////////////
// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disab
#pragma warning(disable:4786)
#include <iostream>
#include <vector>
void main()
{
// Dynamically allocated vector begins with 0 elements.
INTVECTOR theVector;
// Add one element to the end of the vector, an int with the val
// Allocate memory if necessary.
theVector.push_back(42) ;
}
cout << " ]" << endl ;
theVector [ 42, 1 ]
The sample code below illustrates how to use the vector::size and
vector::capacity STL functions in Visual C++.
Required Header:
<vector>
Prototype:
Description:
The sample declares an empty vector of integers. It adds a single
integer element to the vector, and then shows information about the
vector's size, maximum size, and capacity. It reserves storage for
1000 elements and displays the same information about the vector.
Finally, it resizes the vector to 2000 elements, and then displays
the information.
Sample Code:
////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// Remax.cpp: Illustrates vector::reserve, vector::max_size,
// vector::resize, vector::resize, and vector::capacit
//
// Functions:
//
// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disab
#pragma warning(disable:4786)
#include <iostream>
#include <vector>
void main()
{
// Dynamically allocated vector begins with 0 elements.
INTVECTOR theVector;
// Add one element to the end of the vector, an int with the val
theVector.push_back(42) ;
cout << "theVector's size is: " << theVector.size() << endl;
cout << "theVector's maximum size is: " << theVector.max_size()
<< endl;
cout << "theVector's capacity is: " << theVector.capacity() << e
}