-
<< 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.
-
<< is just a normal operator of a class that you can overload like any other operator. :confused:
-
<< 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.
-
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.
-
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'.:(
-
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.