誰もあなたが望む解決策を提供できませんでしたが、私はあなたのためにそれを考案しました。 この関数は、C文字列のファイル名をとり、ファイルを開き、内容を読み取ります。 t.containerに割り当てることができるint *を返します。楽しい。
int* read(char* filename)
{
// open file
ifstream f;
f.open(filename, ios::binary);
// get file size
f.seekg (0, ios::end);
int length = f.tellg();
f.seekg (0, ios::beg);
// allocate new int*
length = (length -(sizeof(int)*2))/sizeof(int);
int* buf = new int[length];
for(int i = 0; i < length; ++i)
{
// create byte array to hold bytes
unsigned char* temp = new char[sizeof(int)];
stream.read((char*)temp, sizeof(int));
// convert byte array to int
for(int j = 0; j < sizeof(int); ++j)
{
buf[i] = buf[i] + (temp[j] << (j*8));
}
delete[] temp;
}
f.close();
return buf;
}
どのようなデータですか?あなたはどこから読んでいますか? *「ダイナミックデータ」*とはどういう意味ですか? – Nawaz
'std :: vector'は最後のメンバですか?あなたの質問は、デシリアライゼーションとして「ダイナミック」データを格納することと同じように思えます。 –
arrsizeを知らずに、配列の代わりにintのベクトルを使用できます。 – DumbCoder