c++再探string之eager-copy、COW和SSO方案

大家可以确定下面的输出什么吗?

                string a = "hello world";
		string b = a;
		if (a == b)
		{
			cout << "true"<<endl;
		}
		else
		{
			cout << "false"<<endl;
		}

		if (a.c_str() == b.c_str())
		{
			cout << "true" << endl;
		}
		else cout << "false" << endl;

		string c = b;
		c = "";
		if (a.c_str() == b.c_str())
		{
			cout << "true" << endl;
		}
		else cout << "false" << endl;

		a = "";
		if (a.c_str() == b.c_str())
		{
			cout << "true" << endl;
		}
		else cout << "false" << endl;

		return 0;

vs2017 debug x64 输出 T F F F
g++ 4 输出 T T T T

https://www.cnblogs.com/cthon/p/9181979.html

posted @ 2021-01-14 10:20  Yan_Hao  阅读(112)  评论(0编辑  收藏  举报