ANSI/ISO C++ Differences

Topace used Ask the Experts™
Hey Again all -

This isn't really a question, as much as it is a topic for discussion.  I am wondering about the differences between normal C++, and ANSI/ISO C++.  My instructor in a course right now is teaching the ANSI/ISO C++, but when I originally learned C++, I learned it differently.

For one thing, there is no namespace topics.  When I #include a standard header, I use #include <standardheadername.h> rather than just #include <standardheadername>.  I also noticed that there are no stupid "using" statements, so cin and cout are just recognized as such, rather than std::cin and std::cout.  

Can anyone tell me the other major differences?  Which is better to become familiar with?  Should I just use ANSI/ISO C++ for the time being to placate my instructor, and actually use regular C++ after the course is done with?  

Just kinda need some advice here, because I see a lot of people with the older (or what I consider to be older) #include statements.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

I'm not sure what you're saying here--are you saying your instructor is using ".h" in his #includes, or that he isn't? AFAIK the standard method for including header files in C++ is WITHOUT the .h extension, and this applies to all modern C++ compilers.

Fact is, the ANSI/ISO standard is the one which is used by compiler manufacturers (unless they happen to be Microsoft :-)) to define how their compilers work, so you would be better off using the ANSI version than any version you may have learnt before.

The ANSI/ISO C++ contains at least since 1996 the rule that all librarys ( with exeption of new and delete )  go into the namespace std.

therefore use always

#include <iostream>

To defeat the pollution of the global namespace don't:

using namespace std;


using std::cout; using std::endl;

instead. Which is also more closely at the python and java notation of importing only the parts you need.

at you can order copys of the standarts.
he is saying that his instructor isn't using.

for one thing Topace, what u learn and what he teach is not conflicting, and that does not mean it is different.

the standard states that "BLAH BLAH BLAH" as stated by EOL already. but the standard ALSO states that for standardheadername.h are also supported for old c headers (NOTE but not for the C++ headers). In this case, u do not have to use the using statement, and these headers automatically uses the using std; statement.

for e.g.

#include <stdio.h>

is equivalent to

#include <cstdio>
using namespace std;

note that

#include <iostream.h>

is not valid because iostream is a C++ header, (though u can use it in borland compilers which is a 'nice' extension to the language)
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.


At least in VC++ you can use <iostream.h> . But I do not recommend it.

Do also note that you can run into bad trouble if you interchange .h and not .h files by random. There are more differences to it. Compare #include <string> and #include <string.h> .

After all, what's the purpose of a standard if you don't use it altough it's supported by all compilers today?

Of course the standard for this topic in C++ is backward compatible, as are most replaced features. Yet you should still use the new notation, because support for the old header in the standard is a legacy system, and the proper usage is what will stay for a long time.

After all you don't want to see ?: instead of if, #defines instead of typedefs, Structs with functions pointers instead of classes, void* instead of template functions, etc..

EOL: What's wrong with the ?: syntax? I've used it myself numerous times...

Generaly spoken, nothing's wrong with it. It just helps a lot to obfuscate your code if you use it more often then realy needed. As do macros, void*, etc..

I tend to follow the idea of making things as simple as possible.

>>At least in VC++ you can use <iostream.h> . But I do
>>not recommend it.

To add to this comment; most compilers support the iostream.h (*.h) version of C++ headers, but they're not part of the standard, and they're functionallity is different from one compiler to the next.
So you should never use the *.h version of the C++ header, regardless of the compiler's support for these non-ANSI standard C++ headers.

>>There are more differences to it. Compare #include
>><string> and #include <string.h> .
The string.h is not the best example, because you should be able to mix <string> with <string.h>
One is referencing the C++ header, and the other should be referencing the C header.

Now if you mix <iostream.h> with <iostream> that's when you can run into problems.  One is including the NON-ANSI C++ version of iostream, and the second one is including the C++ Standard header version of iostream.
Since you should never use the *.h version of the C++ headers in the first place, mixing *.h with extensionless versions should not be an issue.  More to the point, that should just be an added reason why you don't want to use the (C++) *.h version in the first place.

>>  I am wondering about the differences between normal C++, and ANSI/ISO C++.

There is no "normal C++".  There is standard C++ (ISO) and there are non-standard "dialects".  You must have encountered one of the early dialects, from before the standartization.

>> I use #include <standardheadername.h>

Yep, pre-standard headers.  Don't use them.

>> I also noticed that there are no stupid "using" statements, so cin and cout are just recognized as such, rather than std::cin and std::cout.  

See above, the standard requires all standard C++ identifiers to be in the std namespace.  Older iterations didn't.  "using" is a kludge.

>> Should I just use ANSI/ISO C++ for the time being to placate my instructor

Use the standard C++, otherwise your code will not be portable and will not work on different compilers.


Here is something I don't understand.  If I were to use the statement:

#include <iostream>

I understand that this is referencing the iostream STANDARD HEADER.  However, if I were to use the statement:

#include "somefilename.h"

I would be referencing a USER-DEFINED HEADER FILE name somefilename.h.

What is the difference with using the statement:

#include <stdio.h>

If i utilize this statement, it is asking the compiler to include the contents of the file stdio.h into my code, correct?  So why, if the standard is to include all standard headers in the STD namespace, would it not be pertinent to have it as <stdio> rather than <stdio.h>?  If the include statement is referencing a file, I was under the impression, at least with the standardization, that you would place in it double quotes, rather than <>.  If the stdio file is a standard header, then how come it must still use the .h extension?  I am somewhat confused as to why there are all these different variations of the same command.  


I'm not an expert on the standard, but stdio.h is NOT a C++ header--it's an old-style C header, which theoretically you should never need to use in a C++ application anyway. It's only the C++ standard library (iostream etc.) which has this ANSI-standard thing of not including the .H.
#include "something" pastes the contents of 'something' into your source.  #include <something> is similar, but it searches for 'something' in the location of the standard headers first.

Now there are naming CONVENTIONS for headers.  C files usually use 'something.h' as headers.  The early C++ (before it was standardised) used the same convention.

However, the standard introduced namespaces.

So, the old <iostream.h> defined cin and cout to be in the global namespace (remember, early C++ had no other namespaces) but the standard mandated them to be in the std:: namespace.  Also, some library classes were changed (iostreams, for example).

The problem was, how to introduce the change without breaking existing sources?

The solution was simple: make another set of headers with a different naming convention and allow implementors to keep the old one for compatibility.

So <iostream> is the header for the standard C++ I/O stream, while <iostream.h> is the old, pre-standard, header.  Also, to keep with the convention, you can include C headers by prepending their names with 'c' and omitting the '.h'

So in standard C++, you usually do the following:

#include <string> // a standard C++ header
#include <cstring> // a standard C++ header, imports the C header <string.h>
#include <windows.h> // a proprietary header from a "common" directory
#include "MyStuff.h" // your header from the current directory.

So, to answer your recent questions:

1) <stdio.h> is a C header, not a C++ one.  As C++ strives to be compatible with C you can still use it or use the <cstdio> wrapper instead.

2) According to the standard, the standard headers are not necessarily files, the compiler may be tailored to recognise them internally.  However, when you use quotes, the compiler will first search for files in the project directory/ies.  Therefore, use "" for your own headers and <> for the standard headers.

Remember, the .h is just a convention.  #include "something.weird" will work just as well.

>>1) <stdio.h> is a C header, not a C++ one.  As C++
>>strives to be compatible with C you can still use it or
>>use the <cstdio> wrapper instead.
That comment COULD be a little misleading.

stdio.h is part of the C++ standard, and therefore it is a C++ header.
**However**, it is not a C++ STD or a standard template library header.

Moreover, the <stdio.h> (*.h) version of the C headers are considered deprecated, and new code should use <cstdio> version.

As all the C standard libraries are incorporated into the C++ standard, I find continuous use of "a standard C header which is not a standard C++ header" too tedious.


Thanks to everyone for helping me out with this topic.  I am going to give additional points to the following people for their input:


Look for seperate questions in the C++ programming area for more details

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial