|
发表于 2020-4-9 10:00:02
|
显示全部楼层
char* p="hello";
*p的内容是不能改的,c风格字符串在这里是const的,所以你要用p指向令一块内存
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <iostream.h>
using namespace std;
main()
{
char* p="hello";
char *q;
q=new char(10);
q[0]=0x20;
q[1]=0x00;
strcat(q,p);
p=q;
cout<<p<<endl;
system("pause");
delete q;
} |
|