0

我刚开始学习 C++,我注意到当我学习时cout << "Some text" << endl; endl 并不粗体。我想确保这不是问题,并且不会导致任何未来的问题。

4

1 回答 1

1

Do not (<---- this intentionally bold!) use std::endl! Ever. It has no place in C++. It was a good idea but it is being abused. If you want a newline, use '\n'. If you want a flush, use a std::flush. Here is a more thorough explanation.

I don't know about Eclipse but I'd assume that it highlight keywords in bold: std::endl isn't a keyword. It is just a function (well, actually it is a function template but the details really don't matter) with a specific signature (std::ostream&(std::ostream&)) pointers to which are treated special when using it with an output operator on a std::ostream: the operator will just call the function with the stream as argument. These functions are called manipulators.

于 2014-12-21T02:28:18.763 回答