Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!ditka!zinn!nuucp From: mjv@objects.mv.com (Michael J. Vilot) Newsgroups: comp.lang.c++ Subject: RE: Binary Search Using seekg/tellg Message-ID: <1273@zinn.MV.COM> Date: 10 Apr 91 11:42:20 GMT Sender: news@ditka.chicago.com (Pulitzer at ditka) Lines: 32 >From brunix!sdm >Newsgroups: comp.lang.c++ >Message-ID: <71329@brunix.UUCP> >Organization: Brown University Department of Computer Science > >So how do I implement a binary search using iostream I/O? ... the man >page says that streampos objects don't have to obey the laws of > arithmetic. >What do I do? Scott, The semantics of tellg() and seekg() are more analogous to the ANSI C library functions fgetpos() and fsetpos() than to ftell() and fseek(), and the type 'streampos' is akin to 'fpos_t'. The wording of the ANSI C standard is very careful to permit implementation of its library functions on non-Unix systems. We've received comments on the version of iostreams proposed for the C++ standard that we'd better be just as careful in our semantics. To solve your specific problem, I'd suggest that you derive a new kind of streambuf that knows how to do seeking arithmetic on your system, and use that. You can probably implement it in a way that works on all UNIX systems, and localizes your porting efforts if you have to move onto a non-UNIX platform (best case would result in a sibling class for the new platform). Hope this helps, Mike