+ 4

What are bit-shifts and cout?

Hi! I'm not sure if this is a dumb question or not, I'm a newbie :'D. I just don't understand how cout works and why it's important to print out text. I looked it up online and found that it's an output stream and that it 'overloads the left bit shift operator'. Does that mean that the left-bit shift operator is always running? If so, why does it always have to be running? Sorry I'm asking something that's probably very obvious but I've searched online and I'm a bit overwhelmed by all of the information there is out there. Thank you very much in advance!!

27th May 2018, 4:12 PM
CodeMonkey
2 Réponses
+ 4
Cout prints text, maybe usefull for noob debugging, but for a real programming I guess you wouldn't use it that much, unless an error appears maybe. Bitshift operators. It's just in the name. Take some bits and shift them with a bitshift operation. (Some bitshifttutorials can be found in this app, just search for it) I hope this cleared some of it for you. Let me know if you got any other questions.
27th May 2018, 4:20 PM
***
*** - avatar
+ 3
bitshift left: if you have the number(in binary) 101 for example and you do a bitshift left by 1 you get 1010, if you bitshift left by 2. you get 10100(its a little more complex because if you have for example a char(8 bit) and this number 1000 0000 and you do a bitshift left by 1 you get an undefined behavior) an operator is just a function like + where you dont have to write it like this +(5,4) but can write it line this 5+4(only certain symbols are operators in c++). ostream is a class, but you cant bitshift an object, so you can define the bitshift operator to do whatever you want if the left argument(in this case) is an object of type ostream(like cout). this is called operator overloading. in c++ it is defined to print text. a stream is just an abstraction that allows you to write a stream of characters or to get a stream of characters. in this case cout is a object of type ostream that represents the standart output. so ostream overloads << to write stuff to itself and cout is a instance of ostream so << writes stuff to cout which is the start output. it is useful for creating terminal programms
27th May 2018, 4:39 PM
Max
Max - avatar