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
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
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;

int
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 hellostr.cc
$ ./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