Boost logo

Boost Users :

From: Louis Caston (louis_at_[hidden])
Date: 2003-06-10 07:12:44


This is very nice :)
  -----Original Message-----
  From: Alex Henderson [mailto:Alex.Henderson_at_[hidden]]
  Sent: Tuesday, June 10, 2003 6:38 AM
  To: Boost-Users_at_[hidden]
  Subject: RE: [Boost-Users] [crc] Simple example please

  Superb!

  Thanks,
  Alex

> -----Original Message-----
> From: Vladimir Prus [mailto:ghost_at_[hidden]]
> Sent: 10 June 2003 06:08
> To: boost-users_at_[hidden]
> Subject: [Boost-Users] [crc] Simple example please
>
>
> Hi Alex,
>
> > I'd like to calculate a value for a cyclic redundancy check (crc) for
a
> > number of files.
> >
> > This isn't going to be transmitted anywhere, I simply want to
> compare the
> > values to see whether the files are exactly the same. I know I
> can simply
> > check byte for byte, but I've got a few thousand files and it's
> easier to
> > calculate the crc for each and see whether any are the same first.
>
> Here's the function that I use for the same purpose. Might not be
optimal,
> but works:
>
> unsigned file_crc(const string& name)
> {
> #if defined(__GNUC__) && __GNUC__ < 3
> ifstream ifs(name.c_str(), ios::binary);
> #else
> ifstream ifs(name.c_str(), ios_base::binary);
> #endif
> if (!ifs)
> return 0;
> else {
> using namespace boost;
>
> crc_32_type crc32;
> int c;
> while( (c = ifs.rdbuf()->sbumpc()) != -1)
> crc32.process_byte(char(c));
> return crc32.checksum();
> }
> }
>
>
> I believe some example of this kind should be included... Daryle, what
do
> you think?
>
> HTH,
> Volodya
>
>
>
>
> Info: <http://www.boost.org>
> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
> Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
>
>

        Yahoo! Groups Sponsor

  Info: <http://www.boost.org>
  Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
  Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>

  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

[Non-text portions of this message have been removed]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net