c++ - How to do file I/O with std::vector<bool>? -
i need implement boolean data container store large amount of variables. suppose use char*
, implement c-style macro accessors prefer have wrapped in std::
structure. std::bitset<size_t>
not seem practical has fixed-during-compilation size.
so leaves me std::vector<bool>
optimized space; , has nice bool-like accessor.
is there way directly feed pointer
fwrite()
?and how 1 file input such vector?
and lastly, data structure when lot of file i/o needed?
what random file access (
fseek
etc)?
edit: i've decided wrap std::vector<unsigned int>
in new class has functionality demanded requirements.
- is there way directly feed pointer fwrite()?
no, can std::fstream
std::ofstream f("output.file"); std::copy(vb.begin(), vb.end(), std::ostream_iterator<bool>(f));
- and how 1 file input such vector?
using std::fstream
std::ifstream f("input.file"); std::copy(std::istream_iterator<bool>(f), {}, std::back_inserter(vb));
- and lastly, data structure when lot of file i/o needed?
no, vector<bool>
data structure purpose. see http://howardhinnant.github.io/onvectorbool.html
- what random file access (fseek etc)?
what it?
Comments
Post a Comment