结构体中使用string的错误

来源:互联网 发布:2016最多差评的淘宝店 编辑:程序博客网 时间:2024/06/04 18:14
typedef struct temp
{
string x;
int y;
}nnx,*pnnx;
pnnx p=new nnx[10];
sprintf((char*)p[0].x.c_str()," thread send msg: hello.\r\n");

delete[] p;

p=NULL;


//结构体x初始化时默认为空字符串,x.size()为0,在vs2008下使用sprintf可以编译通过,但其实是越界的,后面delete时会出错。

0 0