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.

  1. is there way directly feed pointer fwrite()?

  2. and how 1 file input such vector?

  3. and lastly, data structure when lot of file i/o needed?

  4. 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -