0

This is a part of a c++ program:

cout<< "Width:" << Width << "\n";
cout << "Length: " << Length << endl;

what does the "\n" do in oppose to endl; ?

also,
when do you use void main instead of int main at the beginning of the program?

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by invisal
0

>what does the "\n" do in oppose to endl; ?
endl forces the stream to be flushed, which means that the characters will be written immediately. "\n" doesn't flush the stream, so it's possible that if something happens to interrupt the program between the time you write the characters and the time the stream is flushed, you'll lose the output.

Generally you don't have to worry about using endl because the stream will be flushed at reasonable times for cout, or you should be using cerr for unbuffered output.

>when do you use void main instead of int main at the beginning of the program?
Never. Anyone who does it is wrong.

0
int main()
{
   // code here
}

int main() is standard while void main() is not standard. It is good habit to use int main() instead of void main().

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.