Is there a tab equivalent of std::endl within the standard library?

matthewrdev picture matthewrdev · Feb 27, 2014 · Viewed 79.6k times · Source

Using C++, is there an equivalent standard library constant for '\t' like there is for a newline?

Ideally:

std::stringstream ss;
ss << std::tab << "text";

If not, why is this the case?

(I'm aware I can just insert a '\t' but I'd like to sate my curiosity).

Answer

Brian picture Brian · Feb 27, 2014

No. std::endl isn't a newline constant. It's a manipulator which, in addition to inserting a newline, also flushes the stream.

If you just want to add a newline, you're supposed to just insert a '\n'. And if you just want to add a tab, you just insert a '\t'. There's no std::tab or anything because inserting a tab plus flushing the stream is not exactly a common operation.