Thread: What's the difference?

  1. #1
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448

    Question What's the difference?

    Hi all,
    I was wondering, whatīs is the difference between:

    #include <iostream>
    #include <cstring>

    and using

    #include <iostream.h>
    #include <string.h>

    I mean, donīt they do the same thing? I know the first ones are known as standard headings. Which is better to use?
    Thanks in advance.
    And yes, Iīve searched the forum.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    The first are better if you are going to be programming in C++, those are now standard. Things are in namespace std with the no .h headers, while they aren't with the oldstyle headers including the .h.

    Conform to the standard, use the new style headers.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >whatīs is the difference between
    The first two are current C++ headers and are subject to new additions to the language. If you want to program in correct ISO standard C++ then use the new headers.

    >Which is better to use?
    If you have access to the current headers then use them instead of the older ones.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Ok, thanks. Now I know I should use the 'no .h headers'. I've also seen that with the new ones you have to put
    using namespace std;
    and std::out or things like that. Is there a website that explains it or can you do it in the post?
    TIA
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  5. #5
    Registered User dizolve's Avatar
    Join Date
    Dec 2002
    Posts
    68
    A namespace is pretty much a set of names that have been declared in the program at some point. It's a container and every library is only supposed to declare things in its own namespace. I guess for orginazation. "std" is the standard library namespace.

    So, if you wanted to use 'cout' of the std namespace, you do:

    Code:
    using namespace std;
    
    cout << "blah" << endl;
    OR

    Code:
    std::cout << "blah" << endl;
    The difference is that when you have 'using namespace std;', it puts you in that namespace so that functions you call are checked from there and you don't have to prefix them with std::.

    You can declare your own namespaces, as so:

    Code:
    namespace MyNewNameSpace {
    void function();
    int variable;
    };
    Hope this helps.

  6. #6
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448

    Lightbulb

    Thanks a lot. It's all clear now. I will be creating my new programs according to the standard now.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Review required for program of date difference
    By chottachatri in forum C Programming
    Replies: 6
    Last Post: 10-31-2008, 11:46 AM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. how to get difference of digits
    By Leeman_s in forum C++ Programming
    Replies: 5
    Last Post: 12-20-2001, 08:32 PM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 06:55 AM