Original Post
Perhaps i''m doing something astoundingly stupid, but why aren''t these two programs working properly?
writer:
reader:
Tile.h:
When i run the writer, then run the reader, i get this output:
#include <fstream>
#include "tile/Tile.h"
using namespace std;
int main()
{
ofstream fout("test.map",ios::binary);
if(!fout) cout<<"Error, can''t open test.map"<<endl;
Tile t;
t.x=100;t.y=250;t.w=54;t.h=123;t.img="nice";
for(int i=0;i<100;i++){t.x=i; fout.write((char*)&t,sizeof t);}
return 0;
}
#include<fstream>
#include"tile/Tile.h"
using namespace std;
int main()
{
ifstream fin("test.map");
if(!fin) cout<<"Error";
Tile t;
while(!fin.eof()){ fin.read((char*) &t,sizeof t); cout<<t.x<<endl;}
return 0;
}
class Tile
{
public:
Tile();
char *img;
int x,y;
int w,h;
};
Tile::Tile(){;}
0 1 2 3 4 5 6 7 8 9 10 11 12 -100663296 -100663296 -100663296With those last lines being repeated about 60 times more.