0
嗨我想表达这个成C++向量<位集< 8 >> s {s1,s2,...,sn}; n是文件中元素的编号。所以,我让cnt来计算文件中的元素。 所以,我做了这个代码。但我认为我的代码是不正确的。但我不知道如何解决这个问题。我怎么能表达这个元素到c + +
int cnt;
for (int x = 0; x < sizeof(files)/sizeof(files[0]); x++) {
std::ifstream f;
f.open(files[x].c_str(), std::ios::in);
if (f.good()) {
while (!f.eof()) {//end of file check
f >> str;
bitset<8> s(str);
cnt++;
str.clear();
}
f.close();
}
for (int i = 0; i < cnt; i++){
vector<bitset<8>> s{ s[i] };
}
}
参见[?为什么是的iostream :: EOF算错了一个循环条件中(http://stackoverflow.com/questions/5605125/why-is -iostreameof-loop-condition-considered-wrong) –
[从文件中读取字符串并将其转换为bitset <12>](http://stackoverflow.com/questions/43381239/read-string-from-file -and-turn-into-bitset12) – chbchb55
你最后一个for循环并没有做任何有用的事情。 – chbchb55