Fastest way to write large STL vector to file using STL

Posted by ljubak on Stack Overflow See other posts from Stack Overflow or by ljubak
Published on 2009-11-07T13:52:36Z Indexed on 2010/05/30 12:12 UTC
Read the original article Hit count: 620

Filed under:
|

I have a large vector (10^9 elements) of chars, and I was wondering what is the fastest way to write such vector to a file. So far I've been using next code:

vector<char> vs;
// ... Fill vector with data
ofstream outfile("nanocube.txt", ios::out | ios::binary);
ostream_iterator<char> oi(outfile, '\0');
copy(vs.begin(), vs.end(), oi);

For this code it takes approximately two minutes to write all data to file. The actual question is: "Can I make it faster using STL and how"?

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl