首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

delete有关问题

2012-04-30 
delete问题C/C++ code#include stdafx.h#include iostreamusing namespace stdint _tmain(int argc,

delete问题

C/C++ code
#include "stdafx.h"#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){    char *p=new char[30];    p="I love you";    cout<<p<<endl;    delete[] p;  //此处出错;    p=NULL;    return 0;}

问题:为什么会报错?请高手解释原因!

[解决办法]
p="I love you";

改成
char *str ="I love you";

strcpy(p, str);
或者
memcpy

热点排行