| An Introduction to GCC - for the GNU compilers gcc and g++ by Brian J. Gough, foreword by Richard M. Stallman Paperback (6"x9"), 144 pages ISBN 0954161793 RRP £12.95 ($19.95) "Answers common questions and provides many useful hints" --- Dr. Gerald Pfeifer (SUSE) -- Technical Editor Get a printed copy>>> |
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).
| ISBN 0954161793 | An Introduction to GCC - for the GNU compilers gcc and g++ | See the print edition |