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