How to construct a std::string from a std::vector<char>?

Solution 1:

Well, the best way is to use the following constructor:

template<class InputIterator> string (InputIterator begin, InputIterator end);

which would lead to something like:

std::vector<char> v;
std::string str(v.begin(), v.end());

Solution 2:

I think you can just do

std::string s( MyVector.begin(), MyVector.end() );

where MyVector is your std::vector.