请教关于字符串指针的问题
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char* p = "abc ";
//*p +1 = 'd ';
char* t;
t = new char[strlen(p)+1];
*t = "g ";//为什么不能赋值?
cout < <t < <endl;
return 0;
}
[解决办法]
t是“char*”类型,那么“*t”就是char类型,因此,要写成:
*t = 'g ';
不能写:
*t = "g ";