C++ Programming Code Examples C++ > Code Snippets Code Examples A simple program demonstrating the use of pointers. A simple stack example: push, empty, pop and top A static member variable example. A string demonstration: assignment, concatenate, compare A switch statement in action A vector may allocate more memory than it currently needs. A while Loop - Generate a random number between 0 and 9 Absolute Value Calculation Abstract base class Abstract classes by virtual function with no body Access a vector using an iterator. Access control under inheritance Access out-of-range element Access the elements of a vector through an iterator. Accessing a Vector Through an Iterator Accessing Character Elements of an STL String Accessing Characters In Strings Accessing Data in a File Accessing static members without an object. Accumulate value in a vector Add a friend extractor for objects of type MyClass. Add an else part to the if statement Add elements in a list to a set Add elements in a multiset to a list Add elements in a set to a list add method to struct Adding Strings Addition operator in cout Additional meanings for the + and = operations Address class: class definition and implementation This example show how to declare and use an array of an object An Array of Pointers to Class An array-based output stream An Example of Exception Handling An example that uses typeid for base and derived classes An example that uses typeid on a polymorphic class hierarchy An Example with Two Generic Data Types An exception can be thrown from outside the try block Another example of a conversion function Another example of read() and write() and illustrates the use of gcount( ) Page 1 Page 2 Page 3 Page 35