C++ Examples (ANSI/ISO Standard Version)

Copyright C. S. Tritt, Ph.D.


Linked are four C++ programs that illustrate some of the major features of the language. For more information on many of these language features, see my C++ Quick Reference Page.

Some of these examples use function prototypes and put function definitions after main(). An alternate approach is to skip the function prototyhpes and put function definitions before main(). The prototype approach scales up better, while the functions before main() approach is more convenient for small programs.

sum.cpp swap.cpp
stdlib.cpp arrays.cpp
strings.cpp complex.cpp
comments.cpp cppstrings.html
cstrings.cpp cstrings2.cpp
stlstrings.cpp stlstrings2.cpp
stringswitch.cpp polytropic.cpp
formatedio.cpp rectangle.cpp

The program sum.cpp illustrates:

Return to Table of Contents

The program swap.cpp illustrates:

Return to Table of Contents

The program stdlib.cpp illustrates:

Return to Table of Contents

The program arrays.cpp reads from file asum.in and illustrates:

Return to Table of Contents

The program strings.cpp illustrates:

Return to Table of Contents

The program complex.cpp reads from file complex.dat and illustrates:

Note: Modern C++ has a complex template class (defined in <complex>).

Return to Table of Contents

The program comments.cpp reads text from the file sometext.txt and illustrates:

Return to Table of Contents

The web page cppstrings.html discusses various ways in which to handle textual data in modern C++.

Return to Table of Contents

The program cstrings.cpp illustrates:

Return to Table of Contents

The program cstrings2.cpp illustrates:

Return to Table of Contents

The program stlstrings.cpp illustrates:

Return to Table of Contents

The program stlstrings2.cpp illustrates:

Return to Table of Contents

The program stringswitch.cpp illustrates:

Return to Table of Contents

The program polytropic.cppreads data from the file ideal.dat and illustrates:

Return to Table of Contents

The program formatedio.cpp illustrates:

Return to Table of Contents

The program rectangle.cpp illustrates:

Return to Table of Contents

Among the "advanced" C++ topics not covered in these examples are:


Send comments and suggestions about these examples to: Charles S. Tritt, Ph.D.
This page last updated 9/26/99