string跟指针
string和指针#include iostream#include stringusing namespace stdint main(){string ahellocha
string和指针
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a="hello";
char *b=a;//a不是一个地址吗?为什么这样赋值不行呢
cout<<b;
system("pause");
return 0;
}
[解决办法]a是一个std string模板类对象 不是直接地址
[解决办法]char*b=a.c_str();这样就可以了
[解决办法]a是一个string对象,不是地址。
把
string a="hello";
改成
char a[] = "hello";或char* a = "hello";
应该可达到你想要的情形。
[解决办法]很可能是string对=操作符进行了重载