Container and STL containers

The following std::vector code gives errors

 int main() { std::vector<const double> VectDouble; VectDouble.push_back(2.34); VectDouble.push_back(2.33); VectDouble.push_back(2.32); for(std::vector<const double> VectDouble::iterator i=VectDouble.begin();i!=VectDouble.end();++i) std::cout<<*i; } 
+6
c ++ vector stl templates
source share
2 answers

STL container elements must be assignable and copyable.

const does not allow assignable . Remove const and try compiling the code again.

Also change std::vector<double> VectDouble::iterator to

std::vector<double>::iterator

+13
source share

VectDouble is the name of the variable.

change

 for(std::vector<const double> VectDouble::iterator i=VectDouble.begin();i!=VectDouble.end();++i) 

to

 for(std::vector<const double>::iterator i=VectDouble.begin();i!=VectDouble.end();++i) 

or

 typedef std::vector<const double> vector_t; for(vector_t::iterator i=VectDouble.begin();i!=VectDouble.end();++i) 
+2
source share

All Articles