C++ and standard C++

Differences between C++ and Standard C++
The traditional C++ and the Standard C++ are very similar. The differences
between the old-style and the modern style codes involve two new features: new-
style headers and the namespace statement. Here an example of a do-nothing
program that uses the old style,
/* A traditional-style C++ program */
#include < iostream.h >
int main( ) {
 /* program code */
return 0;
}
New headers
Since C++ is build on C, the skeleton should be familiar, but pay attention to the
#include statement. This statement includes the file iostream.h, which
provides support for C++’s I/O system. It is to C++ what stdio.h is to C.
Here the second version that uses the modern style,
/*
A modern-style C++ program that uses
the new-style headers and namespace
*/
#include < iostream>
using namespace std;
int main( ) {
/* program code */
return 0;
}
First in the #include statement, there is no .h after the name iostream. And
second, the next line, specifying a namespace is new.
The only difference is that in C or traditional C++, the #include statement
includes a file (file-name.h). While the Standard C++ do not specify filenames.
Instead the new style headers simply specify standard identifiers that might be
map to files by the compiler, but they need not be. New headers are abstractions
that simply guaranty that the appropriate prototypes and definitions required by
the C++ library have been declared.
Since the new-style header is not a filename, it does not have a .h extension.
Such header consists only of the header name between angle brackets:
< iostream >
< fstream >
< vector >
< string >
Standard C++ supports the entire C function library, it still supports the C-style
header files associated with the library. That is, header files such as stdio.h and
ctype.h are still available. However Standard C++ also defines new-style
headers that you can use in place of these header files. For example,
Old style header files Standard C++ headers
< math.h > < cmath >
< string.h > < cstring >
Remember, while still common in existing C++ code, old-style headers are
obsolete.
Namespace
When you include a new-style header in your program, the contents of that header
are contained in the std namespace. The namespace is simply a declarative
region. The purpose of a namespace is to localise the names of identifiers to avoid
name collision. Traditionally, the names of library functions and other such items
were simply placed into the global namespace (as they are in C). However, the
contents of new-style headers are place in the std namespace. Using the
statement,
using namespace std;
brings the std namespace into visibility. After this statement has been compiled,
there is no difference working with an old-style header and a new-style one.
Working with an old compiler
If you work with an old compiler that does not support new standards: simply use
the old-style header and delete the namespace statement, i.e.
replace: by:
 #include < iostream> #include < iostream.h >
Posted on by