Find the answer to your Linux question:
Results 1 to 9 of 9
Hello all, I was reading about namespaces and it was stated that the iostream is nested inside the namespace std. The book firmly says that if I don't use: using ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    namespaces


    Hello all,

    I was reading about namespaces and it was stated that the iostream is nested inside the namespace std. The book firmly says that if I don't use:
    using namespace std;
    then my program will not work when I use cout and cin. I have actual codes that use iostream but don't have the syntax "using namespace std." Can anyone tell me exactly what is going on?

    bp
    The best things in life are free.

  2. #2
    Just Joined!
    Join Date
    Nov 2002
    Location
    USA
    Posts
    99
    Backwards compatibility is my first guess. iostream was placed in the namespace std after the standard template libraries became part of C++. As far as I know, iostream is supposed to be implemented in two ways. One is the old way using the header file 'iostream.h', the other is the new way that uses the namespace std and the header file 'iostream'

    If you use the old header
    #include <iostream.h>
    you would not have to include the statement
    using namespace std

    but if you use the STL header
    #include <iostream>
    you would have to include the statement
    using namespace std

    I just tried it both ways as above, but both ways allowed me to use iostream without using namespace std. It seems that g++ has not implemented this correctly, or is just not compliant with the latest ANSI C++ standard, which is probably the standard that your book is using. It may be that the designer of g++ decided to keep the compiler compliant with the older standard of C++ on this issue.

    I just looked at the iostream.h file. The iostream classes were not defined inside namespace std. I guess that's why it's not requiring the namespace. Also, I found the 'iostream' file and it just includes the header for 'iostream.h'. In my experience when it comes to the C++ libraries the only way to find out what is really going on is to look at the code. Anyway, don't take my word for it. Read the code for your own benefit, too.
    Try this to find the file:
    find /usr/include -name 'iostream.h'

  3. #3
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    include

    Slant6,

    I currently am installing debian so I don't have access to those files but I'll look at them later on when I'm done with installation.
    If what you say is true and iostream just includes iostream.h inside namespace std, then physically, there really is no difference between those two files except for the fact that iostream is defined using namespace. I always thought that iostream was a new version of iostream.h and that there were differences in the actual code. I'm beginning to realize that the books that I'm reading are not accurate. As Yoda would say "Very disappointing this is."

    bp
    The best things in life are free.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Nov 2002
    Location
    USA
    Posts
    99
    Yes, very disappointing this is.
    Good luck with the debian installation. I've been thinking about moving to debian too!

  6. #5
    Just Joined!
    Join Date
    Dec 2002
    Location
    Saweeden
    Posts
    2

    Re: namespaces

    Quote Originally Posted by bpark
    Hello all,

    I was reading about namespaces and it was stated that the iostream is nested inside the namespace std. The book firmly says that if I don't use:
    using namespace std;
    then my program will not work when I use cout and cin. I have actual codes that use iostream but don't have the syntax "using namespace std." Can anyone tell me exactly what is going on?

    bp
    Ok, here's the thing:

    If you use new headers, like <iostream>, you need to either use
    "usign namespace std;" or "std::cout<<'b'";

  7. #6
    Just Joined!
    Join Date
    Jul 2002
    Location
    Madison, WI.
    Posts
    36
    I've been hearing a lot of good things about debian as well. I've never tried that distro b4.

  8. #7
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    namespace and debian

    X86MeOneMoreTime wrote:

    Code:
    Ok, here's the thing&#58; 
    
    If you use new headers, like <iostream>, you need to either use 
    "usign namespace std;" or "std&#58;&#58;cout<<'b'";
    Try NOT using 'using namespace std' when using iostream or any of the new header files. The program will still run fine. I'm even using the -Wall option in g++ and I get no warnings. I just recently purchased my fourth C++ book by Barnje Stroustrup and after I read about this, I'll clarify this if I can.


    slacker wrote:

    Code:
    I've been hearing a lot of good things about debian as well. I've never tried that distro b4.
    It definetly was worth the switch. Everything is manual so you learn a lot more about Linux rather than other distros. I first used Redhat and decided to port over because they fused Gnome and KDE. After previous failures at installing debian, I was going to install Mandrake but I decided that debian should be given another chance due to their excellent package system 'apt-get'. Honestly, the installation was the hardest part. Then I had to configure X and load modules ... blah blah ... things that I never knew how to do in Redhat. I've only used Redhat since 7.0 - 8.0 and I can say that none of them were really stable enough for my taste. My friends told me that version 6.x for Redhat were fine but after 7.x was released, it wasn't the same. Debian's stable release is STABLE. Normally I don't use software until after six months have passed but they really test their packages.

    This page deals with a thorough installation:
    http://osnews.com/story.php?news_id=2016

    Enjoy,
    bp[/b]
    The best things in life are free.

  9. #8
    Linux Enthusiast
    Join Date
    Jun 2002
    Location
    San Antonio
    Posts
    621
    it isn't just them that are "fusing" GNOME and KDE. Check out freedesktop.org. Everyone is doing it, and it seems like a Good Thing. All .desktop files are becoming unified, and will be put in specific places. Icon themes are merging rather nicely (I have been working with that a little bit).

    Why it is a Good Thing:
    Remember when GNOME first came out? Of course you do, everyone remembers that. Okay, I don't remember it either. It was circa 6 years ago, KDE was starting to gain acceptance over WindowMaker, people really started to like the environment. Then some Open Source Nut (don't know exactly who) pointed out that KDE was built off of QT. The old license for QT was closed somehow, I forget what the stipulations were, but the FSF declined their license as "free" because you couldn't use it for commercial purposes without paying TrollTech money. Or something like that. So GNOME was started, kind of playing off of where KDE would eventually fall short. They chose ORBit to impliment their own CORBA backend, whereas KDE made their own Object Broker Architecture, which wasn't as well thought out, and not as flexible as CORBA. Details details . . . Either way, about a year and a half ago TrollTech finally gave in and released QT-2.2 (I think) and all QT versions thereafter under the full GPL. Now GNOME has no reason to be upset at KDE, and they realized that both of them had good things going on in the other world. KDE realized that GNOME had a great SVG rendering engine that was embeddable into galeon/nautilus/anything. GNOME realized that KDE had a themeing setup that was far superior to theirs. They both realized that the next version they were going to release would need to incorperate a lot of changes they were thinking of, so they both bumped up a full version number. GNOME2 KDE3. Both of which look _really_ good. Okay, I am done with my rant for now. I can't gaurantee any of this is correct, but this is just what I have heard.
    I respectfully decline the invitation to join your delusion.

  10. #9
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    desktop politics

    Wassy,

    Well, I guess the fusion of the wasn't so bad. I remember using RH8 and GUI was a definte improvement over the old desktops. The use of anti-aliasing and new icons provided an eye candy for the pc desktop. The only thing I wish they did with that was give an option explicitly just for KDE or just for Gnome like they did in the previous versions.
    I'd actually consider RH8 once its more stable. That's the real reason for abandoning it. Package installation could be made easier like apt-get but that's really a problem with most vendors not just Redhat. I once tried installing evolution with RPMs. That was nearly impossible.
    Although I always bad mouth Redhat, I know that I'll one day get the Redhat certification. For home, I'm never going to use anything but debian. Even Linux himself uses Redhat(work) and Suse(home).

    bp
    The best things in life are free.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •