我寫的一個示例代碼,並在列表的push_back它總是導致信息轉儲 這是我的代碼:列表的push_back一個結構,它包括字符串類型核心
#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()
。我不知道爲什麼。謝謝
問題不在於'push_back',它是'memcpy'。你真的不想使用它。 – juanchopanza
push_back實際上推送了你傳遞的對象的一個副本,所以跳過使用'pack',而只是'mVodList.push_back(packet);'並且完成它。 –