Answer the question
In order to leave comments, you need to log in
Is it possible to use endl instead of "\n" in C++?
Is it possible to write endl instead of "\n"?
cout << "Hi" << endl << "world" << endl;
endl means the end of the line, but I did not understand what kind of idea it is, about the end of the line which is in the terminal or in the code?
Answer the question
In order to leave comments, you need to log in
They both serve the same endl and \n the same purpose in C++ - they insert a newline. However, the key difference between the two is that endl is cleared each time the output buffer is called, but \n does not.
Anything that needs to be output is first queued in the output buffer and then written to the device (hard drive, monitor, etc.),
clearing the queue in the process.
https://ru.wikipedia.org/wiki/CP866
https://ru.wikipedia.org/wiki/Windows-1251
https://ru.wikipedia.org/wiki/UTF-8
Have a fun weekend
Correction. Posted in the wrong window.
The behavior depends on the operating system and the mode of opening the file
Sorry, I accidentally answered the question about using it in a switch.
In your case, it all depends on the operating system and the file opening mode
Opening a file in text mode should cause std::endl to be converted to the appropriate line ending for your platform. Your problem is that newline is appropriate for your platform, but the files you create aren't intended for your platform.
I'm not sure how you plan on overloading or changing endl, and changing its behavior would certainly be surprising for any developers new to your project. I'd recommend switching to win_endl (should be a simple search-and-replace) or maybe switching from a standard ostream to a Boost.Iostreams filtering stream to do the conversion for you.
Is it possible to write endl instead of "\n"?
but I didn’t understand what kind of idea we are talking about, about the end of the line which is in the terminal or in the code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question