quick question

This is a discussion on quick question within the C++ Programming forums, part of the General Programming Boards category; i just said the use of "using" and "std" can be avoided easily by including iostream.h Not wanting to teach ...

  1. #16
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    i just said the use of "using" and "std" can be avoided easily by including iostream.h
    Not wanting to teach anyone a correct but highly technical issue is not an excuse to teach an erroneous solution, I guess...

  2. #17
    Registered User
    Join Date
    May 2008
    Posts
    9
    Quote Originally Posted by Elysia View Post
    You can also do...
    using std::cout;
    using std::cin;

    And you won't have to worry about that either. It will make it possible to just type "cin" or "cout".
    Many would argue against importing namespaces, but that's an entirely different issue. As long as you're starting out, it will probably not be of an issue to you.

    Ok, thanks for making it clear, I will be using:

    Code:
    using namespace std;
    for now, or the alternative you mentioned.


    I am currently reading C++ without fear. I switched from Accelerated C++, because I found it too fast paced for my taste. Anyway, I was confused because one author used std:: on every cin and cout line, the other(author of c++ without fear) imported namespace instead.

  3. #18
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Elysia View Post
    No, that's not true. Some compilers (such as Visual Studio) does NOT have iostream.h any longer. It's deprecated, and nowmore unstandard. You should not use it under any circumstances.
    Really? What if the only compiler you have access to does not support the modern standard? You use what you have.

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,596
    "You should not use it under any circumstance if your compiler supports iostream. If your compiler does not support iostream and you have the ability to upgrade compiler to a newer ones that supports iostream, then it is recommended to do so.
    Please note that 'iostream' and 'iostream.h' is not the same."

    Better?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Elysia View Post
    "You should not use it under any circumstance if your compiler supports iostream. If your compiler does not support iostream and you have the ability to upgrade compiler to a newer ones that supports iostream, then it is recommended to do so.
    Please note that 'iostream' and 'iostream.h' is not the same."

    Better?
    Sure.

    I spontaneously react to all blanket statements, don't mind me

    EDIT: This is pretty much why the using namespace directive was invented. If code needs to work on old and new compilers, you can't use std:: because the old compilers don't know what it means. So you write everything without qualification, and use an #ifdef to turn on "using namespace std" on the platforms that do have modern support.

    Of course, you only do that if you have no choice.

  6. #21
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Here's a very important rule:
    Chapter 59. Don't write namespace usings in a header file or before an #include

    Other than that, putting using blah; or using namespace blah; lines in your .cpp files is mostly a matter of personal preference; however, in some cases it can cause unexpected behavior or hard to find bugs if you import several conflicting namespaces together.
    Explicitely qualifying namespaces is always a safer (but more verbose) option.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21