## 6.3 — Local variables

In lesson 2.4 — Introduction to local scope, we introduced local variables, which are variables that are defined inside a function (including function parameters).

It turns out that C++ actually doesnâ€™t have a single attribute that defines a variable as being a local variable. Instead, local variables have several different properties that differentiate how local . . . → Read More: 6.3 — Local variables

## 5.x — Chapter 5 comprehensive quiz

Quick review

Always use parentheses to disambiguate the precedence of operators if there is any question or opportunity for confusion.

The arithmetic operators all work like they do in normal mathematics. The Modulus (%) operator returns the remainder from an integer division. Prior to C++11, beware of integer division and modulus using negative numbers.

. . . → Read More: 5.x — Chapter 5 comprehensive quiz

## 16.4 — STL algorithms overview

In addition to container classes and iterators, STL also provides a number of generic algorithms for working with the elements of the container classes. These allow you to do things like search, sort, insert, reorder, remove, and copy elements of the container class.

Note that algorithms are implemented as global functions that operate using iterators. . . . → Read More: 16.4 — STL algorithms overview

## 16.3 — STL iterators overview

An Iterator is an object that can traverse (iterate over) a container class without the user having to know how the container is implemented. With many classes (particularly lists and the associative classes), iterators are the primary way elements of these classes are accessed.

An iterator is best visualized as a pointer to a given . . . → Read More: 16.3 — STL iterators overview

## 16.2 — STL containers overview

By far the most commonly used functionality of the STL library are the STL container classes. If you need a quick refresher on container classes, check out lesson 10.4 — Container Classes.

The STL contains many different container classes that can be used in different situations. Generally speaking, the container classes fall into three basic . . . → Read More: 16.2 — STL containers overview

## 17.7 — std::string inserting

Inserting

Inserting characters into an existing string can be done via the insert() function.

string& string::insert (size_type index, const string& str) string& string::insert (size_type index, const char* str)

Both functions insert the characters of str into the string at index Both function return *this so they can be “chained”. Both functions throw out_of_range if index . . . → Read More: 17.7 — std::string inserting

## 17.6 — std::string appending

Appending

Appending strings to the end of an existing string is easy using either operator+=, append(), or push_back() function.

string& string::operator+= (const string& str) string& string::append (const string& str)

Both functions append the characters of str to the string. Both function return *this so they can be “chained”. Both functions throw a length_error exception . . . → Read More: 17.6 — std::string appending

## 17.5 — std::string assignment and swapping

String assignment

The easiest way to assign a value to a string is to the use the overloaded operator= function. There is also an assign() member function that duplicates some of this functionality.

string& string::operator= (const string& str) string& string::assign (const string& str) string& string::operator= (const char* str) string& string::assign (const char* str) string& string::operator= . . . → Read More: 17.5 — std::string assignment and swapping

## 13.2 — Input with istream

The iostream library is fairly complex — so we will not be able to cover it in it’s entirety in these tutorials. However, we will show you the most commonly used functionality. In this section, we will look at various aspects of the input class (istream).

Note: All of the I/O functionality in this lesson . . . → Read More: 13.2 — Input with istream

## Eight C++ programming mistakes the compiler won’t catch

C++ is a complex language, full of subtle traps for the unwary. There is an almost infinite number of ways to screw things up. Fortunately, modern compilers are pretty good at detecting a large number of these cases and notifying the programmer via compile errors or warnings. Ultimately, any error that is compiler-detectable becomes . . . → Read More: Eight C++ programming mistakes the compiler won’t catch