
-----------------------------------
wtd
Mon Nov 08, 2004 8:56 pm

[C++] Things you shouldn't be doing (and what you should)
-----------------------------------
Don't include "iostream.h".

This header, along with many others, have been deprecated by the C++ standard.  This means that they may work now, but aren't guaranteed to work in future compilers that stick to the standard.

Instead...

#include 

Aside from "stdlib.h", you probably won't encounter any standard header files that have the ".h".  You will find this on nonstandard header files, though, including your own, so beware, and when in doubt, ask.
Don't use "cout" or "cin" without "using namespace std".

There are three ways to properly do this:

using namespace std;
std::cout
 using std::cout


More to come.

-----------------------------------
Geminias
Wed Sep 21, 2005 11:28 pm


-----------------------------------
please explain why we should use std, what does std mean and what does namespace mean?  i'm not saying your wrong just want to know why.

-----------------------------------
wtd
Wed Sep 21, 2005 11:46 pm


-----------------------------------
In a C++ program, you can't give two things different names.  It just doesn't work.

So, if you have two different libraries that both want to have the name "copy", you'd have to give them reallyLongAwkwardNames to keepThemFromConflictingWithEachOther.  ;)

Or.... you can use namespaces.  With a namespace, instead of, for instance:  the WoobleSoftCopyRoutine and NinjaStudiosCopyRoutine functions, you might have:

WoobleSoft::CopyRoutine and NinjaStudios::CopyRoutine.

Now, if I'm not using both at the same time, for convenience, I can do something like:

#include 

int main()
{
   using namespace WoobleSoft;

   CopyRoutine();

   return 0;
}

Now, what is "std"?  No, it's not something you catch from doing the reproductive equivalent of using Windows without a firewall.

It's an abbreviation for "standard".  It's a namespace that holds all kinds of useful standard library functions, classes and variables.

-----------------------------------
Geminias
Thu Sep 22, 2005 7:55 pm


-----------------------------------
hey wtd.. i'm using mingw compiler it doesn't compile if i use 

example (this one does compile right)

#include 

int main ()
{
  cout 