C plus plus

From LQWiki
Jump to navigation Jump to search

C++ is a very popular programming language (an extension of the original C) that is commonly used to program many of GNU/Linux's core programs. It's often used to write object-oriented software.

Language features

  • strong type checking
  • namespaces
  • templates
  • operator overloading
  • exception handling
  • The standard library
    • STL
      • containers
      • generic algorithms
      • iterators
    • strings
    • streams
    • numerics
    • The entire C standard library


#include <iostream>
int main()
    std::cout << "Hello, world!" << std::endl;

This displays the phrase "Hello, world!" on the screen, similar to the simpler shell command "echo Hello, world!" used in the Linux console.

Compiling C++ in Linux Environment

To compile your C++ codes, you can use g++ compiler. For more information on how to use g++, view gcc's man page.

$ man gcc

Save the above Hello World code in a file with extension .cpp (say hello.cpp). To compile the above simple code, enter the following at the command prompt.

$ g++ hello.cpp

The compiler will create an executable file called a.out. To execute it type

$ ./a.out

This should print the words 'Hello world!' at your terminal.

Further reading


  • The C++ Programming Language, Bjarne Stroustrup
  • Thinking in C++, Bruce Eckel
  • Effective C++: 50 Specific Ways to Improve Your Programs and Design, Scott Meyers
  • Code Complete, Steve McConnell

See also