Notice: Undefined offset: 15093823 in /var/www/html/qa-external/qa-external-users.php on line 744
Why does endl; bunch up my text yet \n does not? - OnlineGDB Q&A
Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why does endl; bunch up my text yet \n does not?

+2 votes
asked Apr 6, 2025 by (140 points)
I'm running C++, and while I get some unwanted results from using endl; I seem to have fewer problems using "\n" in results

my "" are bunched up.

2 Answers

0 votes
answered Apr 13, 2025 by Peter Minarik (101,340 points)
edited Apr 14, 2025 by Peter Minarik

They should both work.

Could you please share an example with std::endl that does not behave as expected?

0 votes
answered Apr 13, 2025 by 22280680 N N Sibiya (140 points)
Regarding the issue with quotes being "bunched up," it's likely due to the lack of a space after the "\n". You can add a space after the "\n" like this: "\n " to separate the quotes.

Here's an example:

std::cout << "Hello\n" << "World!";
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...