Hi guys,
When i run my programs in c i always use things like

include "stdio"

But then i see things like

include "stdio.h"

and

include <stdio>

I was wondering which one i should use and also why there are so many different ways.

Cheers

Recommended Answers

All 15 Replies

stdio.h is used in vc6.0 and many other old programs.

in VC2008 you use

#include "stdio"

stdio.h is used in vc6.0 and many other old programs.

in VC2008 you use

#include "stdio"

????
Impossible!
No such header as <stdio> (especially "stdio" ).
Standard C stream i/o header is <stdio.h>. In C++ you may include it as <cstdio> - that's all...
It looks like a blind man told to a deaf man about colors ;)

commented: Nice crack about the blind man :) +36

o yes,it is "stdio.h".

what i have learned is that we donot use ".h" in VC2008 like : i use "iostream" not with ".h"

o yes,it is "stdio.h".

what i have learned is that we donot use ".h" in VC2008 like : i use "iostream" not with ".h"

That's not really correct either -- there are thousands of header files with .h extensions used in c++, such as windows.h because there are no equivalent without the .h extension.

The only files I am aware of that lost the .h extension in c++ programs are those in the standard C and C++ libraries. All others still use the .h extension unless the author elected not to use it.

>what i have learned is that we donot use ".h" in VC2008 like : i use "iostream" not >with ".h"
Most of the C-header files like (stdio.h, string.h, math.h,) are now comes with stripped .h and a c added before there name.
stdio.h --> cstdio
string.h --> cstring
math.h --> cmath

Further, there is no <stdio>. it has to be <cstdio> or <stdio.h>
ArkM is right :)

>there are thousands of header files with .h extensions used in c++...
The most interesting thing (for internal use only;)): those thousands of files are not headers! All C++ headers are enumerated in the C++ Standard with the note:

A header is not necessarily a source file, nor are the sequences delimited by < and > in header names necessarily valid source file names

The C++ declares 25 C library headers named with .h. It also provides same "cnamed" headers (without .h, from <cassert> to <cwctype>). All names declared in cnamed headers are placed in the namespace std (and may be in the global namespace).

Strictly speaking, all names in #include "name" directives denote included source files, not headers. Headers are special language or implementation defined preludes (collections of declarations). For example, Windows SDK contains ~1200 included source files or source modules but not headers (look at comments in Windows SDK sources).

Well, it's a common practice to designate included source files (modules) named with .h as headers, but both C and C++ languages never defined that naming convention and never named all included sources as headers.

ArkM you are making a mountain out of a mole hill. Everyone I know calls files with .h extension "header files". And for windows SDK files I use #include <windows.h> , not #include "windows.h" . And even if we do use the quotes I still call them header files.

You can call them source files if you want to, but I don't think may other programmers do.

I know what you mean ;)
However take the C++ Standard and try to search the header term ;)...

In the standard "16.2 Source file inclusion" (my first reference!) it mentions an interesting difference between <header.h> and "header.h". Basically, it says that the "" form may not even be supported, and if it isn't or if it is but the file is not found using that method, then it switches to acting just like <>.

The method (such as the order of directories) by which <> or "" look for "files" (or whatever) is implementation defined. I believe my imp. looks in the current dir first for "", but looks in the other imp.-defined places first for <>.

Also, don't the <iostream.h> forms automatically add a bunch of "using std::xxx" (brining all identifiers into the global namespace) while the <iostream> form does not? Doesn't seem to be in the standard, but that's what my imp. does.

for iostream, many compilers don't evern support iostream.h any more because the ios standards declared it deprecated several years ago.

The <iostream.h> is not a standard header now (for quite a long time).

Apropos, using directive does not bring names into the global namespace. It specifies that the names in the nominated namespace can be used in the scope in which the using-directive appears after the using-directive. In other words, it makes names directly visible in the scope. For example, some names may conflict with global names (it's OK while you don't touch these names but it's impossible if using directive brings names into the global namespace).

I see. Thanks. Just started reading the standard. Kind of jumping around at the moment. Haven't read much about the library. Over 700 pages in the thing! I wasn't expecting that.

Firstly yes, i stuffed up what i was trying to include in the first post. Woops.

But when coding should i use #include <something.h> as a standard or does is change all the time.

If it is a standard header, (like cstdio, iosteram, fstream, string, cmath, cstdio etc.) #include<iostream> instead of #include<iostream.h>

But if your header is non-standard (like gtk.h, sockets.h or myHeader.h) then you should #include<gtk.h> or #include<socket.h>

If the header file is home-made, you should perhaps
#include "myHeader.h" which usually tells the compiler to look for the file in the current directory rather than the standard include directory.

commented: Thanks +1

Ah thats a lot, that helps me out greatly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.