아무도 내가 원하는 해결책을 줄 수는 없었지만 나는 그것을 고안했습니다. 이 함수는 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'를 마지막 멤버로 사용합니까? 귀하의 질문에 대한 "역동적 인"데이터를 deserialization로 저장에 대한 많은 것 같다. –
arrsize를 모른 채 배열 대신 int의 벡터를 사용할 수 있습니다. – DumbCoder