我写了一个示例代码,当列表 push_back 它总是导致 coredump 这是我的代码:
#include <iostream>
#include <list>
#include <string.h>
using namespace std;
struct FDTinstance
{
int type;
unsigned int expirestime;
unsigned int fileTOI;
string filename;
unsigned int contentlength;
unsigned long long T3;
unsigned long long T1;
unsigned long long T4;
unsigned long long sessionstarttime;
};
struct PacketInfo
{
unsigned int port;
unsigned long long arrivetime;
unsigned int syncType;
unsigned short timeStamp;
unsigned short packNum;
unsigned int packCount;
unsigned int TSI;
unsigned int TOI;
FDTinstance fDTinstance;
};
int main(int argc, char* argv[])
{
struct PacketInfo packet;
packet.fDTinstance.filename = "http://123.com";
packet.syncType=1;
packet.fDTinstance.expirestime = 100;
packet.fDTinstance.fileTOI = 0;
struct PacketInfo pack;
memcpy(&pack, &packet, sizeof(packet));
mVodList.push_back(pack);//cause core
return 0;
}
如果我使用const char* filename
,程序是好的。但是当我使用字符串类型时,程序将以push_back()
. 我不知道为什么。谢谢