P
paul.anderson
This code doesn't work - the first retrieval of t2 returns valid data,
the subsequent do not. Please help!!!
int main(int argc, char* argc){
struct Test{
int i;
int j;
intk;
int l;
}
Test Test1;
Test1.i = 99;
Test1.j = 777;
Test1.k = 12345;
Test1.l = 876;
fstream fout;
fout.open("test.txt", ios:ut);
for (int i=0; i<10; i++)
fout.write(reinterpret_cast<char*>(&Test1), sizeof(Test));
fout.close();
fstream fin;
fin.open(test.txt", ios::in);
for(int i=0; i<10; i++){
char c[sizeof(Test)];
fin.get(c, sizeof(Test));
Test t2;
// === THIS COPY OF t2 CONTAINS CORRECT DATA FIRST TIME BUT NOT
SUBSEQUENT
// TIMES!!!!!!!!!
memcpy(&t2, c, sizeof(Test));
}
}
the subsequent do not. Please help!!!
int main(int argc, char* argc){
struct Test{
int i;
int j;
intk;
int l;
}
Test Test1;
Test1.i = 99;
Test1.j = 777;
Test1.k = 12345;
Test1.l = 876;
fstream fout;
fout.open("test.txt", ios:ut);
for (int i=0; i<10; i++)
fout.write(reinterpret_cast<char*>(&Test1), sizeof(Test));
fout.close();
fstream fin;
fin.open(test.txt", ios::in);
for(int i=0; i<10; i++){
char c[sizeof(Test)];
fin.get(c, sizeof(Test));
Test t2;
// === THIS COPY OF t2 CONTAINS CORRECT DATA FIRST TIME BUT NOT
SUBSEQUENT
// TIMES!!!!!!!!!
memcpy(&t2, c, sizeof(Test));
}
}