Cocos2d-X v2.2.5
Hi guyz. I have this:
//initialize vector
std::vector playerIn(3);
and let’ say that vector is filled with chars now. like
//fill vector with chars
playerIn[0] = ‘c’ ;
playerIn[1] = ‘a’ ;
playerIn[2] = ‘t’ ;
now HOW DO I CONVERT THIS VECTOR to a STRING so it’ll appear like:
“cat”
thnx guyz!
std::vector<char>* data;
char * xmlData = new char[data->size()+1];
memset(xmlData, '\0', data->size()+1);
std::string * temp = new std::string();
for (std::vector<char>::iterator iter = data->begin(); iter != data->end(); iter++)
{
temp->push_back(*iter);
}
This is the way i’m using now, but there are standard C++ in-built functions too. Try googling.
P.S If anyone have better approach plz post.