This tutorials introduces you to the C++ Standard Template Library (STL) including how to use I/O streams, file streams, string streams, strings, vectors, lists, maps, iterators, and algorithms.
Tutorial Details:
The C++ Standard Template Library
The C++ language is not a simple language. In fact, many would argue it is a somewhat overcomplicated language. Nevertheless it can be used to write beautiful code. On top of that it is so widespread that example code and libraries (free ones, too) are all over the Internet.
To be able to write working programs in C++, you'll need a decent grasp of the subtleties of the language itself. That is not what this article is about. On top of understanding the language, it helps tremendously to be able to use the standard library correctly. That is what this article is about. You'd be surprised how many people program in C++ but ignore most of its features. That is not necessarily a bad way to program, but you can save yourself a lot of work by using all of the language.
A reason many people avoid the standard library are that they are worried about performance. Especially game developers often suffer from a syndrome where they do not trust any code that they can not mentally compile to assembly instructions on the spot. The conveniences of the standard library and all those templates, they think, just can't be fast. In fact, the whole standard library was designed with performance in mind, and often things will compile to code that is just as efficient as a solution you write yourself. Another very common (and somewhat related) reason not to use standard library functionality is that people refuse to use anything they did not program themselves in their programs. While it is very educational to make everything yourself at least once, if you want to be productive you'll have to start using other people's code, it is available and it is well tested.
The most important parts of the C++ standard library are its containers, iterators, the iostream classes and the algorithms. All classes and functions in the standard library are inside the namespace 'std'.
When passing non-trivial objects to functions or returning them you should get in the habit of passing by reference. This is basic C++ stuff but you really must know this to use standard containers. Do take care not to return references to local objects that will vanish when their scope exits. Also, when you do not intend to modify an object, pass it by const reference, that way temporary objects can be passed, the compiler will complain if you try to pass a temporary object by non-const reference.
All examples in this article use code without indicating any function it is in, and to make things worse I write #include at the same level too. I do this mostly to avoid unneccesary clutter and keep the code readable. This is not valid C++ though, if you want to actually compile it add an 'int main(){ ... }' function around the code (not the includes).
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: C and Cpp Programming in C and Cpp Introduction to the C++ Standard Template Library Tutorial
View Tutorial: C and Cpp Programming in C and Cpp Introduction to the C++ Standard Template Library Tutorial
Related
Tutorials:
Accelerate your Java apps! - JavaWorld - September 1998
Accelerate your Java apps! - JavaWorld - September 1998 |
The battle of the container
frameworks: which should you use? - JavaWorld - January
1999
The battle of the container
frameworks: which should you use? - JavaWorld - January
1999 |
Smart object-management saves the
day - JavaWorld November 1999
Smart object-management saves the
day - JavaWorld November 1999 |
JavaWorld article about
JavaCC
JavaWorld article about
JavaCC |
JSP templates - JavaWorld September 2000
JSP templates - JavaWorld September 2000 |
C# : A language alternative or just J--? (part1)
C# : A language alternative or just J--? (part1) |
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000 |
Language improvements
and models make
great Java - JavaWorld
Language improvements
and models make
great Java - JavaWorld |
Integrate Java and C++ with Jace
Integrate Java and C++ with Jace |
Check out three
collections libraries
Check out three
collections libraries |
JSP Standard Tag Library eases Webpage
development
JSP Standard Tag Library eases Webpage
development |
The J2EE 1.4 Tutorial
The J2EE 1.4 Tutorial is a guide to developing enterprise applications for the Java 2 Platform, Enterprise Edition (J2EE) version 1.4. Here we cover all the things you need to know to make the best use of this tutorial. |
JSP 2.0: The New Deal, Part 3
JSP 2.0: The New Deal, Part 3
More Flexible JSP Document Format Rules
The JSP specification supports two types of JSP pages: regular JSP pages containing any type of text or markup, and JSP Documents, which are well-formed XML documents; i.e., docum |
libbraille
Libbraille is a computer shared library which makes it possible to easily develop for Braille displays. It provides a simple API to write text on the terminal, directly draw dots, or get the value of keys pressed on the Braille display. |
JFormula 2.9 - Math expression API
JFormula 2.9 - Math expression API
JFormula is a Java library for evaluating various expressions (boolean, math, if/then/else...).
A lot of companies chose JFormula like EADS Space Transportation. |
JTwain
JTwain will implement a Java interface to the the Win32 C DLL TWAIN acquire methods. |
10 Minutes Guide to Ant
10 Minutes Guide to Ant
10 Minutes Guide to Ant
Previous Tutorial Index Next
Introduction
Well for the next 10 minutes get ready to devote to the ant guide. This will make some sence to the ant.
Ant is a free tool under GNU Licence and is |
Building Web Application With Ant and Deploying on Jboss 3.0
Building Web Application With Ant and Deploying on Jboss 3.0
Building Web Application With Ant and Deploying on Jboss 3.0
Previous Tutorial Index Next
In this lesson I will show you how to build you web application and install on the Jboss 3.0 |
UltraLightClient Community Site
Community-driven Wiki site for UltraLightClient Code Snippets and Contributions
If you want to contribute, please go to Register as Committer. There is no support for the content on this site by Canoo. Committers agree that the code can be used free of c |
New Technical Articles: 64-bit Programming on Solaris 10 OS for x86 Platforms
Four technical articles describe the new Sun Studio 10 software's 64-bit programming features on the Solaris 10 OS for x86 and AMD64 platforms. Important issues regarding the AMD64 ABI (Application Binary Interface), debugging, migration to 64-bits, and p |
|
|
|