c++ - Data in Vectors -


i have 2 vectors both of different types i.e.

1. std::vector<project3::vertex<vertextype, edgetype>> vertice2; //contains list of vertices 2. std::vector<std::string>temp12; 

my requirement want store data vertice2 temp12. tried out lot many different ways, getting error. type casting didn't work out me.

latest tried temp.assign(g1.vertice2.begin(), g1.vertice2.end());

error: 'std::basic_string<_elem,_traits,_ax>::basic_string(const std::basic_string<_elem,_traits,_ax> &)' : cannot convert parameter 1 'project3::vertex<vertextype,edgetype>' 'const std::basic_string<_elem,_traits,_ax> &'   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xmemory  208 1   project_3_revised 

you have vector of apples you're trying store in vector of oranges. apples aren't oranges, , that's basic problem.

either need make temp vector<vertex...>, or need convert each vertex object string, , store resulting strings. if trying cram vertex in vector<string> without converting it, give up. can't , should not try this. you're trying put battleship in pencil cup.

if go conversion, using std::transform along conversion function of own devising pretty straightforward way this.

psudocode follows:

std::string convertvertextostring(const vertex& vx) {   std::stringstream ss;   ss << vx.prop_a << " " << vx.prop_b;   return ss.str(); }  int main() {   ...    std::transform(vertice2.begin(), vertice2.end(), back_inserter(temp12), &convertvertextostring);  } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -