endl error

Started by
18 comments, last by Adam Hamilton 17 years, 11 months ago
arrrrrrrrrrrrrrrrrrrrr
does the code tag work?

std::cout

and lets try a quote aswell

std::cout <
Advertisement
fuckin stupid board you cant even post code. !!!!!!!!!!!!!!!!!!!!
AP, I believe there is an issue only with AP's as to what the board allows
you to post.

cout <<
has the <> that would otherwize be taken as HTML braces, and as such are cut from the final AP post.
The difference between '\n' and std::endl is that std::endl will flush the buffer (std::cout's in this case).
The problem with using '\n' is that it doesn't flush the buffer, so if the program crashes, there may be text still in the buffer that has not been displayed on the screen. This is misleading because you might assume that the error occurred before the text should have been displayed, when really the error occurred after.
'endl' is system independent, so basically using endl (end-ell) will add the appropriate line break for the operating system it is running on.

'\n' is not system independent, different operating systems may have a different
line break character.

so using 'endl' is the best and 'safer' option.
this tag

<br>code here<br><br><br>(without the spaces)<br><br>works fine for me.
Quote:Original post by electronix
'endl' is system independent, so basically using endl (end-ell) will add the appropriate line break for the operating system it is running on.

'\n' is not system independent, different operating systems may have a different
line break character.

so using 'endl' is the best and 'safer' option.


Not true - the c runtime will convert \n into the appropriate endline character - the reason to use std::endl is for the flush
Quote:Original post by MadDog72
The problem with using '\n' is that it doesn't flush the buffer, so if the program crashes, there may be text still in the buffer that has not been displayed on the screen. This is misleading because you might assume that the error occurred before the text should have been displayed, when really the error occurred after.


Well... you *should* be outputting "diagnostic" messages to cerr (which is by default not buffered in this way) instead, but your point is otherwise valid. :)
This will work too. I think too many std:: makes programs harder to read.

#include <iostream>int main(){ using std::cout; using std::endl; cout << "Hello there.\n"; cout << "Here is 5: " << 5 << "\n"; cout << "The manipulator endl writes a new line to the screen."; cout << endl; cout << "Here is a very big number:\t" << 7000 << endl; cout << "Here is the sum of 8 and 5:\t" << 8 + 5 << endl; cout << "Here's a fraction:\t\t" << (float) 5/8 << endl; cout << "And a very very big number:\t"; cout << (double) 7000 * 7000 << endl; cout << "Don't forget to replace Jesse Liberty with your name...\n"; cout << "Jesse Liberty is a C++ Programmer!\n"; return 0;}

This topic is closed to new replies.

Advertisement