I understand you can not use operator+
to concatenate an integer to a std::string
without converting it to a char*
or std::string
.
But why does adding an integer returns the tail of a string?
#include <iostream>
#include <string>
int main()
{
std::string x;
x = "hello world" + 3;
std::cout << x << std::endl;
}
Prints: lo world
If you change: x = "hello world" + 8;
We print: rld
What's the reasoning behind this? Undefined behavior?