我读了一些GCC bugreport,那里有人在谈论"vstring".搜索WEB我注意到http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/vstring_8h.html.
有人可以详细说明它有用和用于什么?为什么用它代替std :: string?
请考虑以下示例:
int main()
{
string x = "hello";
//copy constructor has been called here.
string y(x);
//c_str return const char*, but this usage is quite popular.
char* temp = (char*)y.c_str();
temp[0] = 'p';
cout << "x = " << x << endl;
cout << "y = " << y << endl;
cin >> x;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在visual studio编译器和g ++上运行它.当我这样做时,我得到了两个不同的结果.
用g ++:
x = pello
y = pello
Run Code Online (Sandbox Code Playgroud)
在visual studio 2010中:
x = hello
y = pello
Run Code Online (Sandbox Code Playgroud)
差异的原因很可能是g ++ std …