Filling a Deque From a Vector

Hi, I have a quick question about filling a stl deque from a stl vector. I would appreciate it if someone could tell me what I'm doing wrong in this snippet of code. the vector is called lines, and the deque is called testbuffer.


1
2
3
4
5
6
deque<double>testbuffer (10);

 for(unsigned int i = 0; i < lines.size(); i++)
    {
    testbuffer.push_back(lines.at(i)); // this line gives me an error.
    }

This would work fine if lines were a vector<double>.
But I suppose it actually is a vector<string>. You can use lexical_cast to do the conversion:

1
2
3
4
5
#include <boost/lexical_cast.hpp>
[..]
vector<string> lines;
deque<double> testbuffer(lines.size());
transform(lines.begin(),lines.end(),testbuffer.begin(),boost::lexical_cast<double,string>);
Wow, that's very cool. Thanks very much, it works perfectly.
Topic archived. No new replies allowed.