如果使用g++和clang++,我得到++my string==my string##my string--.虽然是MSVC和英特尔编译器++==my string##my string--.
为什么?
#include <string>
#include <iostream>
using namespace std;
string test()
{
string s0 = "my string";
return s0;
}
int main()
{
string s = test();
const char* s1 = test().c_str();
const char* s2 = s.c_str();
cout << "++" << s1 << "==" << s2 << "##" << test().c_str() << "--" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是一个未定义的行为吗?