[英]Concatenation precedence in case of std::string and const char
Is it ok to write the following code?写下面的代码可以吗?
std::string first = "str";
"1" + first + "2" + std::to_string(1).c_str();
Will first
be concatenated with "2" before "2 + std::to_string" concatenation, so there will be no "pointers concatenation" error?在"2 + std::to_string" 连接之前会
first
与"2" 连接,所以不会出现"pointers concatenation" 错误?
Addition is left-associative, so that's加法是左结合的,所以
(("1" + first) + "2") + std::to_string(1).c_str();
In other words, first
will not be concatenated with "2"
, and neither will "2"
(fail to) be concatenated with std::to_string(1).c_str()
.换句话说,
first
不会与级联"2"
,并且也不会"2"
(不)与串接std::to_string(1).c_str()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.