float f; if(read(fd,&f,sizeof(f))==sizeof(f)) printf("%f\n",f); else printf("oops\n");
Provided that it is written as a compatible binary representation.
read for file descriptors, fread for FILE* and istream::read for c++ iostreams. Choose whatever you like:
read(fd,&f,sizeof(f))==sizeof(f) fread(&f,sizeof(f),1,fp)==1 fin.read((char*)&f,sizeof(f)).gcount()==sizeof(f)
Michael Krelin - hacker
source share