- 1

Why is using '<<' before 'endl' correct and why?

Hey, on a sololearn question the following syntax was used. But I don't understand why we need to use '<<' before 'endl'. Can anyone explain? Thanks a lot! int main() { int x; x = 4 + 6; cout << x << endl; }

13th Aug 2018, 5:24 AM
Helina Abye
Helina Abye - avatar
1 ответ
+ 3
Helina Abye Gebreyes endl is the manipulator for new line... where you want new line is to be provided to the endl... if you write cout << endl, it prints new line to console output stream... if you put file pointer in place of cout, endl places new line to that file... coming to << , it's operator which is used for writing to object ( cout or any file pointer)... this << operator allows you to write int, string and new line also to output stream.. one can say that << operator is overloaded to write different data type to output..
13th Aug 2018, 5:41 AM
Ketan Lalcheta
Ketan Lalcheta - avatar