ループに入るたびに変化する u_char 配列と、u_char 配列としてメンバーを持つ構造体があります。u_char 配列のすべての反復を含む構造のベクトルを作成しようとしています。しかし、セグメンテーション違反 (memcpy を使用する場合) または同じ値が複製される (使用しない場合) のいずれかが発生します。ヘルプ?これがコードです
u_char * data; //contains the data I want to copy from each iteration
unsigned char mem1[bytes];
for(int i=0; i<bytes; i++) {
mem1[i] = data[i];
}
struct load l1; //contains one member (pload of type u_char*)
l1.pload = mem1; //this gives me the same value in all elements of the vector
//I also tried using memcpy, like this:
//memcpy(&l1.pload, mem1, bytes); //this gave me a segfault
recd.push_back(l1) //recd is a std::vector<load>
私はそれを次のように印刷します:
for(std::vector<load>::iterator it1 = recd.begin(); it1 != recd.end(); ++it1) {
cout<<"\nhere\n"<<endl;
cout<<it1->pload<<endl;
}