我正在一个项目上,我认为我目前需要操纵位。
整个想法是我正在解析一个二进制文件,我必须提取每个106字节的记录。由于一个文件可以有10条记录,所以我决定将每条记录放入一个位集中(从ifstream获取char并在我的位上附加
`
template <size_t N>class calls : public bin<N> {
std::vector<std::bitset<N>> getFile(const std::string &fileName) override {
std::ifstream in(fileName,std::ios::in|std::ios::binary);
std::vector<std::bitset<CALLS_CHUNK_SIZE>> result;
auto iterator = result.begin();
std::bitset<CALLS_CHUNK_SIZE> bits;
assert(in);
char c;
int counter = 0;
while(in.get(c)){
if(counter == CALLS_CHUNK_SIZE){
result.push_back(bits);
//is there a way to reset my bitset to an empty bitset again so i can keep pushing every new record as a bitset in my vector?
}
bits<<c;
counter++;
}
}
`
您认为这个主意还可以吗?还是我应该做些别的事,使之更有效/更有效/总体上是一个更好的解决方案?
提取数据后,我应该将它们重新解释为字符,数字等...
请注意,代码不完整,我是C ++的初学者。
谢谢!