Copying boost::array<char> to std::string

boost, c++, iterator, stdstring, string

Solution

You can use back_insert_iterator. Assigning to it will call `push_back` function of the underlying container so you don't need to worry with allocating space manually.

std::copy(_buffer.begin(), _buffer.begin()+bytes_transferred, std::back_inserter(data));

Problem

I am trying to cvopy `boost::array<char>` to `std::string`. ``` boost::array<char, 1024> _buffer; std::string data; std::copy(_buffer.begin(), _buffer.begin()+bytes_transferred, data.begin()); ``` which is not working. So I changed it a little bit. ``` char _buffer[1024]; std::string data; std::copy(_buffer, _buffer+bytes_transferred, data.begin()); ``` second one is not working either.

Original source