Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

c++ - How to use boost::crc?

I want to use boost::crc so that it works exactly like PHP's crc32() function. I tried reading the horrible documentation and many headaches later I haven't made any progress.

Apparently I have to do something like:

int GetCrc32(const string& my_string) {
    return crc_32 = boost::crc<bits, TruncPoly, InitRem, FinalXor,
                   ReflectIn, ReflectRem>(my_string.c_str(), my_string.length());
}

bits should be 32.. What the other things are is a mystery. A little help? ;)

question from:https://stackoverflow.com/questions/2573726/how-to-use-boostcrc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Dan Story and ergosys provided good answers (apparently I was looking in the wrong place, that's why the headaches) but while I'm at it I wanted to provide a copy&paste solution for the function in my question for future googlers:

int GetCrc32(const string& my_string) {
    boost::crc_32_type result;
    result.process_bytes(my_string.data(), my_string.length());
    return result.checksum();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...