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).
The std::endl manipulator is defined in <ostream> header. I attempted to clarify the question, I think there is a good question here and it has attracted an excellent answer from Yakk.
std::basic_ostream<CharT, Traits>& endl( std::basic_ostream<CharT, Traits>& os ); Inserts a newline character into the output sequence os and flushes it as if by calling os.
Both endl and \n serve the same purpose in C++ – they insert a new line. However, the key difference between them is that endl causes a flushing of the output buffer every time it is called, whereas \n does not.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With