<< in iostream

This is a discussion on << in iostream within the C++ Programming forums, part of the General Programming Boards category; Let's say I want to use left shift. Does that mean I cannot use iostream header in the same file. ...

  1. #1
    badman
    Guest

    << in iostream

    Let's say I want to use left shift. Does that mean I cannot use iostream header in the same file.

    Another question is that I declare to use iostream header in one source file and not in another source file(2nd) in the same project, will the iostream header in effect in the 2nd file?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    95
    First of all, I don't think I know what you're talking about, but the "left shift" button has nothing to do with iostream.h. Second of all, you will have to include the header in both source files, because a header is just a source code file that can be inserted in another source code file. At least this is how I was taught.
    Think out of the box! Open Source rules!

    -Breach23

  3. #3
    badman
    Guest

    I rephase my questions again.

    left shift symbol is << in C

    However << is for cout in iostream header.

    The second question means I use one header in one source but not in another. Will the header be in effect in these two files of the same project?

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    answers

    Shifting is still safe to do, don't worry about it .

    If you include <iostream> you now have that code attached to your .o file (and later your executable)

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    i'm pretty sure a c++ compiler can distinguish between using "<<" or ">>" for bit shifting and iostream standard i/o. and i wouldn't be surprised if these bit shifting operators, for c, were used for standard i/o for a reason (maybe an expert can fill in here). as for header files, do you mean "project" as in a visual c++ project? if so i have'nt the slightest clue. but i think in general if you say include a "header1.h" in "header2.h", then include "header2.h" in "header3.h", then "header3.h" will also include "header1.h".

    hope i'm right, if not i apologize.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    looks like coz got there first, nevermind my reply.

  7. #7
    badman
    Guest
    Hi greenRoom, what I mean in my 2nd question is,

    header1.h is used in 1st.cpp

    header1.h is not included in 2nd.cpp

    1st.cpp and 2nd.cpp is in the same VC project file.

    Will header1 be or used in 2nd.cpp too?

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    7
    In answer to your second question, no. If the second source file does not include "iostream.h" then it will not be effected by it (unless it includes a file which includes "iostream.h" of course).

    In answer to the first, the '<<' operator is a singular thing. I/O stream classes (and their objects such as 'cout'/'cin') overload the '<<' and '>>' operators. This means that when you use those operators ('<<' / '>>') on stream classes there are member functions that are called because they supercede the default operator handling (which is bit shifting).

    So if you are going to use bit shifting in a statement that uses stream classes, you should probably contain the bit-shifts in parenthesis so they do not get mixed up:

    cout << "X / 2 = " (x >> 2) << endl;

    Hope this helps.

  9. #9
    badman
    Guest
    Thanx Breach23, cozman, greenRoom and icegoblin for your replies.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cout << SunTradingLLC << "is looking for C++ Software Developers" << endl;
    By sun trading in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 04-02-2008, 12:48 PM
  2. Drieving from iostream
    By Thantos in forum C++ Programming
    Replies: 8
    Last Post: 06-23-2004, 05:57 PM
  3. cout << setiosflags(256L) << 123.123;
    By jochen123 in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2002, 11:17 AM
  4. can't cout << hex << 'T'; what's wrong?
    By andre in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2002, 07:53 PM
  5. DJGPP Doesn't include IOSTREAM!!!!!!!!!!!
    By Frenchfry164 in forum Game Programming
    Replies: 12
    Last Post: 10-27-2001, 01:27 PM

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