Results 1 to 6 of 6

Thread: << in iostream

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    Question << 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 be in effect in the 2nd file?

    I think the solution is not to use std namespace. However it is better to seek more opinions.
    Last edited by transcendental; Oct 18th, 2001 at 10:01 PM.
    I'm a VB6 beginner.

  2. #2
    << is just a normal operator of a class that you can overload like any other operator.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    << and >> means left shift and right shift in C.

    If one knows assembly, one knows what shifting means.Nope, I am not trying to overload the << operator.
    I'm a VB6 beginner.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    iostream is a class and the << and >> operators are overloaded just for this class. If you use it with integers for example it will still work.
    And you don't need to know assembler to know what bit shifting is. Every good C programmer knows bit shifting.

    Q2: No, the header is valid only in the module you included it, nowhere else, and it hasn't got anything to do with namespaces.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Well I did not say that one have to know assembly to know shifting.

    "If one knows assembly, one knows what shifting means." != "If one only know C, one don't know shifting."

    I use 'one' instead of 'you' in my previous post, is bcos I don't want to be seen like targeting at filburt1, which I do not.

    Looks like it backfired, my rephrased statement looked like implying all C programmers something bcos of 'one'.
    I'm a VB6 beginner.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's ok, there is no reason to get upset about such a minor issue.
    Another thing: in classes, you can give every operator any meaning you want. It is simply considered as bad manner, except for the bit shifting operators (you usually can't bitshift on a complex object). Therefor they are the i/o operators in the stream classes (also in MFCs CArchive btw) and you could also make a stack class that uses << as push and >> as pop.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width