Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
it is used because if you write cout<<xendl; and this is not correct because it seem that you have a variable named xendl and you want it's value as output and you know that cout<<x endl; it give error because the compiler does not understand space in cout statement so to differentiate two different variable or two different things in cout statement we use << means cascading operator every time and you can also right the statement as cout<<x; cout<<endl;
16th Jun 2016, 10:57 AM
DJ Shiva & DJ Baba Shiv-Shekhar
DJ Shiva & DJ Baba Shiv-Shekhar - avatar
+ 1
well endl is also an object of iostrem class to connect cout and endl u use << or u can also use "\n" for a new line
16th Jun 2016, 8:10 AM
Sardor
Sardor - avatar
+ 1
it's Syntax , when you wanna use iostream, one liner are preferred, because less is more.
17th Jun 2016, 7:41 AM
Moersy
Moersy - avatar
0
agree. maybe you mean after cin?
16th Jun 2016, 6:12 AM
Sardor
Sardor - avatar
0
do you understand the first >>?
16th Jun 2016, 7:59 AM
Sardor
Sardor - avatar
0
dude it must have been cout << x << endl;
16th Jun 2016, 7:59 AM
Sardor
Sardor - avatar
0
so, normally << and >> are bit wise, shifting operators, but under certain functions like cout and endl it's actually a function call. so when you do myFunction(parameters), you make a function call. it's essentially the same thing except it's a special syntax for the cout cin endl and other functions
17th Jun 2016, 9:38 PM
destro