Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ convert vector<int> to vector<double>

What is a good clean way to convert a std::vector<int> intVec to std::vector<double> doubleVec. Or, more generally, to convert two vectors of convertible types?

like image 305
Alan Turing Avatar asked Jun 18 '11 21:06

Alan Turing


1 Answers

Use std::vector's range constructor:

std::vector<int> intVec; std::vector<double> doubleVec(intVec.begin(), intVec.end()); 
like image 186
James McNellis Avatar answered Sep 22 '22 08:09

James McNellis