<iostream> or <iostream.h> ???

Started by
7 comments, last by V3rt3x 21 years, 4 months ago
Erm.. why is there two versions a little differents ? with < iostream > I need to call objects from the std namespace, or if I include < fstream > I can't use ios::nocreate (or I'm a newbie and I don't know how to :x). So why two files (one with extenstion) for a same header ? And then, what is the best to include for portability code ? [edited by - V3rt3x on December 4, 2002 5:33:42 PM]
Advertisement
iostream.h is deprecated. Compilers include it only for backwards compatibility with older code. Use the newstyle (iostream) headers, which include, among other things, support for namespaces.
You should be particularly careful about this stuff especially with regards to iostreams

In Visual C++, v6, including iostream.h gets you the non-templatized, pre-standard version of the stream library.

always use the form unless you KNOW you need the other one for some reason
you should use the ones without the ".h" if possible, since they are the not outdated like the ".h" ones (which are included for backward compatiblity).

as a side note, you can use "std::ios::nocreate" for the < iostream> thing...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
quote:Original post by Miserable
iostream.h is deprecated.

It''s not even deprecated. It was never Standardised. Quite simply iostream.h is not guaranteed to be present and, if it does happen to exist, there''s no guarantees made about what''s in it.
quote:Original post by krez
you should use the ones without the ".h" if possible, since they are the not outdated like the ".h" ones (which are included for backward compatiblity).

as a side note, you can use "std::ios::nocreate" for the < iostream> thing...



std::ios::nocreate fails

Visual C++ 6.0 return this :

C:\...\bitmap.cpp(54) : error C2039: ''nocreate'' : is not a member of ''basic_ios< char,struct std::char_traits< char > >''
C:\...\bitmap.cpp(54) : error C2065: ''nocreate'' : undeclared identifier

I included < iostream > and < fstream >.
quote:Original post by V3rt3x
std::ios::nocreate fails

That''s because there''s no such thing. nocreate is a vendor-supplied extension.
ok, but is there an other choice instead of using ios::nocreate to prevent the function creating a new file?
quote:Original post by V3rt3x
ok, but is there an other choice instead of using ios::nocreate to prevent the function creating a new file?


std::ifstream never creates a file if it doesn''t exist.
std::ofstream always creates a file if it doesn''t exist.

nocreate
- open an ifstream
- if it fails ... return
- otherwise ... proceed

noreplace
- open an ifstream
- if it succeeds ... return
- otherwise ... proceed

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement