Sometimes you will also encounter Std:vector and turn std:string each other in the case of conversion.
First look at vector<char>
how to turn a string:
STD:: vector<char>*data = Response->getresponsedata ();STD::stringRes//Method one for(inti =0; I<data->size (); ++i) {res+= (*data) [i];} res+=' + ';STD:cout<< Res;//Method twoSTD:: vector<char>*data = Response->getresponsedata ();STD::stringRes;res.insert (Res.begin (), Data->begin (), Data->end ());STD::cout<< Res;//Method threeSTD:: vector<char>*data = Response->getresponsedata ();STD::stringResConst Char* s = & (*data->begin ()); res =STD::string(s, data->size ());STD::cout<< Res;//Method fourstringCH ="What a fucking day!"; vector <char>Ta;ta.resize (Ch.size ()); Ta.assign (Ch.begin (), Ch.end ());
String to vector is easier:
vector <char> ta = {‘a’, ‘b‘, ‘c‘};ch.clear();ch.assign(ta.begin(),ta.end());
================================================================
Vector to StringStream
#include <iostream>#include <sstream>#include <vector>#include <string>#include <iterator> //Dummy std::vector of Strings STD:: Vector<std::string>sentence; Sentence.push_back ("AA"); Sentence.push_back ("AB");//Required Std::stringstream Object STD::StringStreamss//Populate STD:: Copy (Sentence.begin (), Sentence.end (),STD::ostream_iterator<STD::string> (SS,"\ n"));//Display STD::cout<<ss.str () <<STD:: Endl;
The string series--std:vector<char> and std:string in the actual combat C + + conversion (vector to StringStream)