Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




7.3 Using the C++ standard library

An implementation of the C++ standard library is provided as a part of GCC. The following program uses the standard library string class to reimplement the Hello World program:

#include <string>
#include <iostream>

using namespace std;

main ()
  string s1 = "Hello,";
  string s2 = "World!";
  cout << s1 + " " + s2 << '\n';
  return 0;

The program can be compiled and run using the same commands as above:

$ g++ -Wall
$ ./a.out 
Hello, World!

Note that in accordance with the C++ standard, the header files for the C++ library itself do not use a file extension. The classes in the library are also defined in the std namespace, so the directive using namespace std is needed to access them, unless the prefix std:: is used throughout (as in the previous section).

  Published under the terms of the GNU General Public License Design by Interspire