結構體中使用string的錯誤
阿新 • • 發佈:2019-01-02
typedef struct temp
{
string x;
int y;
}nnx,*pnnx;
pnnxp=new nnx[10];
sprintf((char*)p[0].x.c_str()," thread send msg: hello.\r\n");
{
string x;
int y;
}nnx,*pnnx;
pnnxp=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時會出錯。