<分区>
我知道您不能使用 operator+
将整数连接到 std::string
而不将其转换为 char*
或 std::string
.
但为什么添加一个整数会返回字符串的尾部?
#include <iostream>
#include <string>
int main()
{
std::string x;
x = "hello world" + 3;
std::cout << x << std::endl;
}
打印:lo world
如果你改变:x = "hello world"+ 8;
我们打印:rld
这背后的原因是什么?未定义的行为?