[英]Eclipse Luna C++ endl
I just started learning C++ and I noticed that when I do cout << "Some text" << endl;
我刚开始学习C ++,我注意到当我做cout << "Some text" << endl;
endl is not bold. endl不大胆。 I want to make sure that this is not a problem and it won't cause any future problems. 我想确保这不是问题,并且将来不会引起任何问题。
Do not (<---- this intentionally bold!) use std::endl
! 不要 (<----这种故意大胆!)使用std::endl
! Ever. 永远。 It has no place in C++. 它在C ++中没有位置。 It was a good idea but it is being abused. 这是一个好主意,但被滥用了。 If you want a newline, use '\\n'
. 如果要换行,请使用'\\n'
。 If you want a flush, use a std::flush
. 如果要冲洗,请使用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. 我不了解Eclipse,但我假设它以粗体突出显示关键字: std::endl
不是关键字。 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. 它只是一个带有特定签名( std::ostream&(std::ostream&)
)的指针(实际上,它实际上是一个函数模板,但细节实际上并不重要),将其与std::ostream
上的输出运算符:该运算符将仅使用流作为参数来调用该函数。 These functions are called manipulators . 这些功能称为操纵器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.