char指针怎么指向string变量

2025-02-28 15:49:22
推荐回答(2个)
回答1:

我怎么可以用?

#include
#include
using namespace std;

int main()
{
string *p;
string msg("hello world!");
p=&msg;
cout << *p << endl;
cout << (*p)[0] < (*p)[p->length()-1] << endl;
system("pause");
return 0;
}

回答2:

string有str()获取char*类型字符串