Why is #include <iostream.h> outdated?

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Why is #include <iostream.h> outdated?

Postby jgbauman » Mon Oct 13, 2003 5:49 am

Why is #include <iostream.h> outdated?

In the early years there was no standard for C++ and all compiler vendors followed only a rough convention of what should be there. But often you couldn't port a program from one compiler/platform easily to another because of annoying little differences. So the high knights of C++ sat down at a round table, discussed a lot and wrote a standard call ISO-C++. It's also known as standard C++, C++98 or most formal: ISO/IEC 14882:1998

In it many of the old header files were standardized so that a given set of instructions could be used regardless of which compiler you use. To differentiate between the old headers and the new ones, the .h was removed from them. So #include <iostream.h> is now just #include <iostream> as well as many others.

As well as the new headers was the inclusion of the standard namespace. Any objects in the new header files, such as cout and endl, are found in the namespace std, and can be accessed either individually:
Code: Select all
#include <iostream>
void f() {
  std::cout << "BLAH" << std::endl;
  // note: standard library identifiers are to be prefixed with std::
}

or individually imported from the namespace std:
Code: Select all
#include <iostream>
using std::cout;
void f() {
  cout << "BLAH" << std::endl;
  // note: prefix std:: not neccesary for cout, but for endl
};

Or everything from the namespace std gets imported, by putting the following line under your includes (not recommended for writing header files)
Code: Select all
#include <iostream>
using namespace std;
void f() {
  cout << "BLAH" << endl;
  // note: prefix std:: not needed at all
};

Then just use cout as normal, without the std:: in front.

Namespaces are useful, but for a beginner who doesn't need to worry about them, just put the using namespace std line under your includes, and you shouldn't need to worry about it for now, just do some reading when you get the chance.

The C++ standard headers are:
  • <algorithm> Many useful algorithms, like std::copy
  • <bitset> Bitset
  • <complex> Complex numbers
  • <deque> Deque containters
  • <exception> Exception handling
  • <fstream> File IO
  • <functional> Function objects
  • <iomanip> IO manipulators
  • <ios> IO base classes
  • <iosfwd> IO forward declarations
  • <iostream> IO streams
  • <istream> Input streams
  • <iterator> Useful iterators, like std::ostream_iterator
  • <limits> Implementation properties
  • <list> List containers
  • <locale> I18 Locales
  • <map> Assiociative containers
  • <memory> Memory managment
  • <new> Dynamic memory management
  • <numeric> Numeric limits
  • <ostream> Output streams
  • <queue> Queue containers
  • <set> Set containers
  • <sstream> String streams
  • <stack> Stack containers
  • <stdexcept> Exception classes
  • <streambuf> Stream buffer classes
  • <string> String classes
  • <typeinfo> Type identification
  • <utility> Utility component
  • <valarray> Arrays of values
  • <vector> Vector containers
  • <cassert> adapted assert.h from C
  • <cctype> adapted ctype.h from C
  • <cerrno> adapted errno.h from C
  • <cfloat> adapted float.h from C
  • <climits> adapted limits.h from C
  • <clocale> adapted locale.h from C
  • <cmath> adapted math.h from C
  • <csetjump> adapted setjump.h from C
  • <csignal> adapted signal.h from C
  • <cstdarg> adapted stdarg.h from C
  • <cstddef> adatped stddef.h from C
  • <cstdio> adapted stdio.h from C
  • <cstdlib> adapted stdlib.h from C
  • <cstring> adapted string.h from C
  • <ctime> adapted time.h from C
  • <cwchar> adapted wchar.h from C
  • <cwctype> adapted wctype.h from C
Links to more documentation on the web:

Thanks to Wizard, who posted the initial version.

As always: Corrections welcome ;-)

Changes:
Added link to GNU libstdc++ docu
Last edited by jgbauman on Mon Oct 13, 2003 8:52 am, edited 1 time in total.
User avatar
jgbauman
 
Posts: 358
Joined: Sat Sep 27, 2003 9:00 am

Postby jgbauman » Mon Oct 13, 2003 5:50 am

If you find it helpful and you have the power make it sticky ;-)
User avatar
jgbauman
 
Posts: 358
Joined: Sat Sep 27, 2003 9:00 am

Postby Wizard » Fri Nov 21, 2003 12:58 pm

I don't know why I didn't think of that sooner.
This is a very useful thread, thank you Jgbauman.
Stickied, unless Loobian says otherwise.
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby RecursiveS » Mon Nov 24, 2003 12:09 pm

Excellent thread Jgbauman :) :)

Have you submitted these articles to Loobian for inclusion/updating of the faqs ????
User avatar
RecursiveS
Site Admin
 
Posts: 1236
Joined: Thu Sep 18, 2003 8:33 am
Location: Dorset, UK


Return to For Beginners

Who is online

Users browsing this forum: Google Adsense [Bot] and 4 guests