Chapter 3 Strings, Vectors and Arrays

Ways to Initialize a string

String Operations


  1. cin discards any leading whitespace, but getline() doesn’t.
  2. size() returns a string::size_type. It is a unsigned type.
  3. Never ever compare size_type with a negative number!

  4. When using “+” operator, avoid following errors

  5. String literals, such as “abc”, are not strings.

Function: decltype()

Returns the type of its operand.

Ways to Initialize a vector

Function: push_back()

Takes a value and “pushes” that value as a new last element onto the “back” of the vector.

vector Operations

Standard Container Iterator Operations

Note: 1. In for loops’ condition part, use != instead of < or >, because all the library containers have iterators that define the == and != operators and most of those iterators do not have the < operator.