Writing booleans to file

Posted by Sara on Stack Overflow See other posts from Stack Overflow or by Sara
Published on 2010-06-09T09:51:43Z Indexed on 2010/06/09 10:02 UTC
Read the original article Hit count: 240

Filed under:
|
|

Hello,

I have a piece of code that gives a runtime error. Can anyone help find out why?

vector<int> intData;
vector<bool> boolData;


for(int i=0;i<19000;i++)
   boolData.push_back(false);


string ofile = "tree.dat";
ofstream fout(ofile.c_str(),ios::out | ios::binary);


if (!boolData.empty()) fout.write((char *)&boolData[0], sizeof(bool)*boolData.size());
fout.close();

It gives the error when it tries to write the file (fout.write).

© Stack Overflow or respective owner

Related posts about c++

Related posts about file