Questions tagged [endl]

For issues relating to the std::endl output-only I/O manipulator.

endl is an output-only I/O manipulator. It inserts a newline character into an output sequence os and flushes the stream. It is defined in the header ostream and part of the namespace std. The behavior is equivalent to calling os.put('\n') and then os.flush().

Minimal example:

#include <iostream>

int main()
{
    std::cout << "Hello World" << std::endl;
    return 0;
}
79 questions
56
votes
2 answers

What is the C++ iostream endl fiasco?

I was listening to a google talk by Andrei Alexandrescu on the D programming language when he threw out a one liner about the "endl" fiasco. I just thought endl was the preferred way to signify the end of a line and flush the buffer for a stream.…
Tod
  • 8,192
  • 5
  • 52
  • 93
37
votes
7 answers

Overload handling of std::endl?

I want to define a class MyStream so that: MyStream myStream; myStream << 1 << 2 << 3 << std::endl << 5 << 6 << std::endl << 7 << 8 << std::endl; gives output [blah]123 [blah]56 [blah]78 Basically, I want a "[blah]" inserted at the front, then…
anon
  • 41,035
  • 53
  • 197
  • 293
19
votes
1 answer

Why does my (C++) compiler want to instantiate my parameter pack class when using std::endl?

Consider the following short program. #include template< typename ... Ts > class foobar { static_assert( sizeof...(Ts) > 0 ); }; template< typename ... Ts > std::ostream& operator<<( std::ostream& o, const foobar< Ts... >& ) { …
Ted Middleton
  • 6,859
  • 10
  • 51
  • 71
15
votes
2 answers

Does new line character also flush the buffer?

I understand that questions like, difference between endl and \n have been answered many times on SO. But they only mention that endl is able to flush the buffer onto the stdout, while \n, does not. So, what I understand by buffer being flushed is…
CaptainDaVinci
  • 975
  • 7
  • 23
12
votes
3 answers

Does std::endl << std::flush have a purpose?

std::flush right after a std::endl is used all over the legacy code I am looking at. When I first saw this, my thought was it is redundant from looking at the description of std::endl and std::flush…
9Breaker
  • 724
  • 6
  • 16
10
votes
1 answer

Differences between std::endl and '\n' for streambuffer implementations

I'm currently trying to implement a subclass of stringbuf to allow the buffer to tokenize for specific chars ('\n' in my case) and undertake an action if this char occurs (dump the message to a logger and clear buffer afterwards in my case). To…
crispinus
  • 115
  • 1
  • 4
10
votes
3 answers

What exactly is flushing?

I'm brand new to coding and programming (started today actually). I've been watching a few videos and reading the beginning to a few books to see which I can click with, but I'm having trouble understanding some of it. One of the videos utilized…
B Mai
  • 101
  • 1
  • 3
10
votes
1 answer

Difference between "endl" and "\n"

Possible Duplicate: C++: “std::endl” vs “\n” I'm wondering if there is any significant difference between these two ways to print newline : cout << endl; //approach1 cout << "\n"; //approach2 Is there any practical difference?
Nawaz
  • 353,942
  • 115
  • 666
  • 851
10
votes
4 answers

C++ stream as a parameter when overloading operator<<

I'm trying to write my own logging class and use it as a stream: logger L; L << "whatever" << std::endl; This is the code I started with: #include using namespace std; class logger{ public: template friend logger&…
José Tomás Tocino
  • 9,873
  • 5
  • 44
  • 78
10
votes
2 answers

std::endl crashes Windows 8, compiled using MinGW

I have 3 computers, two of which use Windows 8. Using the latest version of MinGW's g++ (4.8.1-4) my hello world program freezes whenever I compile and run on the Windows 8 computers but not in Windows 7. #include int main() { …
user1276560
  • 135
  • 1
  • 6
8
votes
4 answers

How we can add a new line in c#

How we can write output on second line in c# ?? How we can write the given code into two lines MessageBox.Show("my name is " + LineBreak, "yazdan" , MessageBoxButton.OK, MessageBoxIcon.Information); How we can start a new line…
Yazdan Haider
  • 975
  • 1
  • 7
  • 10
7
votes
3 answers

Structure of std::endl

I am new to C++ and I am confused about std::endl. When trying to understand what std::endl is, I had faced some resources which told me that it is a function. However, how can a function be deprived of parentheses?
Goktug
  • 855
  • 1
  • 8
  • 21
6
votes
4 answers

Keep getting "error: use of undeclared identifier 'cout' and error: reference to overloaded function could not be resolved

I am writing a sorting program using a host of different functions as y'all can see from my declarations. However, I keep getting these same errors when I try to compile and run my program they are as follows: error: use of undeclared…
Jok3r
  • 163
  • 3
  • 4
  • 8
5
votes
4 answers

std::endl in a string variable?

Hi i want to save multiply lines in a string. I got a string logstring and i want to save multiplay error logs which i later can print in a txt file or as a console output. Is there a possibility to use endl to format a string variable? I searched…
Fabian Patzlaff
  • 103
  • 1
  • 2
  • 7
5
votes
0 answers

C++ output stream not flushed with endl and execution halts

I have a C++ program that contains several cout statements. I have ensured that all of them end with an endl. My problem is that the program seldom halts until a user presses Enter (so I assume that the output buffer isn't always flushed as it…
Bennie
  • 51
  • 2
1
2 3 4 5 6