You got it right, but you can use std::ostringstream
to create your char array.
#include <sstream>
std::ostringstream StringRepresentation;
for ( vector<int>::iterator it = MyVector.begin(); it != MyVector.end(); it++ ) {
StringRepresentation << *it << " ";
}
const char * CharArray = StringRepresentation.str().c_str();
In this case, CharArray
is only for reading. If you want to modify the values, you will have to copy it. You can simplify this by using Boost.Foreach.