|
-
Aug 22nd, 2001, 10:11 AM
#1
Thread Starter
Addicted Member
Header with '.'?
Why doesn't everyone start using (unless you have an older compiler) the:
#include <iostream> //notice no .h
using namespace std;
?
Was just wondering if their is a reason between the two.
-
Aug 22nd, 2001, 10:27 AM
#2
transcendental analytic
It's a filename, it doesn't need to be .h it could be .banana if you want
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 22nd, 2001, 11:12 AM
#3
Frenzied Member
That would be cool in a weird kind of way. If I ever write a language, header files will be .banana 
The reason most people don't use the STL versions is because:
a) it's a new(er) style of syntax that old tutorials/books don't mention
b) anyone using M$ VC++ will see the .h included in any help file examples, since that will use M$'s header files (slightly different from the ANSI ones).
Harry.
"From one thing, know ten thousand things."
-
Aug 22nd, 2001, 11:17 AM
#4
Yeah, Harry, and source files could be .monkey =P.
Z.
-
Aug 22nd, 2001, 11:47 AM
#5
I just bought a C++ book, and it states that using the ANSI standard versions (no .h) and namespace std has very strong debugging and OOP differences. The ANSI version is actually the OOP version.
-
Aug 22nd, 2001, 01:04 PM
#6
I was taught to use the <iostream.h> syntax in University... (which was 4 years ago.)
What's the difference with using just <iostream>? Is there any specific ways you have to call functions using this? Benefits? Downsides? And what does std do?
Destined
(A guy who switched his majors from Computer Science to Physics, 4 years ago... )
-
Aug 22nd, 2001, 01:53 PM
#7
For example, there is a major difference between <string.h> and <string>.
The first one is the C include, which contains functions for string (char array) manipulation.
The second one is actually a C++ string class + the functions from the C include file.
-
Aug 23rd, 2001, 02:44 AM
#8
Frenzied Member
The old .h style header includes got deprecated a while back, but AFAIK it was standard to use .h style includes in C++ up until then. I have no idea when the governing bodies of C++ decided to drop the .h, but it could have been less than 4 years ago I guess.
I was taught to use .h too, but I was being taught C, not C++.
std is the standard namespace. When you include STL headers, their contents go into the std namespace (I think that goes for all STL headers, but I'm not sure). Namespaces are very useful to prevent naming conflicts by placing things in their own custom scopes. The using directive can place you in a different namespace to the default namespace (the global namespace), which can ease your typing by preventing you from having to fully qualify every variable and function from that namespace you use with the scope.
So, without the using directive you would type:
std::cout
but with it you could write just:
cout
Anyway it's good practice to use the non-deprecated versions of things, so use the new style.
Harry.
"From one thing, know ten thousand things."
-
Aug 23rd, 2001, 12:20 PM
#9
Monday Morning Lunatic
And as a qualification, you should never use using namespace whatever; in a header file, because that can really mess things up as it applies it to every source file it's included in. The using directive only otherwise applies to the current source file.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|