I'm attempting to import a large amount of data from a file into a boost::dynamic_bitset. To accomplish this, I was hoping to use an istream_iterator which matches the block size of the dynamic_bitset (uint32_t).
As shown below, I setup my ifstream using the location of the file to be imported. However, once I initialize the istream_iterator with the ifstream, the ifstream's fail bit is set.
Any advice regarding why this is occurring?
ifstream memHashes (hashFileLocation, ios::in | ios::binary);
if(memHashes.is_open() == false || memHashes.good() == false) { break; }
std::istream_iterator<uint32_t> memHashesIt(memHashes);
std::istream_iterator<uint32_t> memHashesEOFIt;
According to cplusplus.com:
failbit is generally set by an input operation when the error was related to the internal logic of the operation itself, so other operations on the stream may be possible. While badbit is generally set when the error involves the loss of integrity of the stream, which is likely to persist even if a different operation is performed on the stream. badbit can be checked independently by calling member function bad.
Edit:
The hash contains 160 bit hashes, produced by a SHA1 implementation in a separate C application. There are a few thousand hashes in this file. I would like to read 5 blocks of 4 bytes, instead of 20 blocks of 1 byte (hence my use of uint32_t as the block size) I've pulled in the relevant code from the C application, which shows the hashes being produced and then written to a file:
#define HASH_SIZE 20 // 160 bits / 8 bits per byte = 20 bytes
FILE *fp;
fp = fopen(hash_filename, "wb");
if (!fp) {
MSG("Hash dump file cannot be opened");
fclose(fp);
return NULL;
}
uint8_t *p;
unsigned char hash[HASH_SIZE];
SHA1((unsigned char*)p, LENGTH_TO_HASH, hash);
fwrite(hash, HASH_SIZE, 1, fp);