Fastest way to write large STL vector to file using STL

后端 未结 7 720
一个人的身影
一个人的身影 2021-02-06 06:53

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:

ve         


        
7条回答
  •  别跟我提以往
    2021-02-06 07:16

    There is a slight conceptual error with your second argument to ostream_iterator's constructor. It should be NULL pointer, if you don't want a delimiter (although, luckily for you, this will be treated as such implicitly), or the second argument should be omitted.

    However, this means that after writing each character, the code needs to check for the pointer designating the delimiter (which might be somewhat inefficient).

    I think, if you want to go with iterators, perhaps you could try ostreambuf_iterator.

    Other options might include using the write() method (if it can handle output this large, or perhaps output it in chunks), and perhaps OS-specific output functions.

提交回复
热议问题