c++11 - Weird std::vector::reverse_iterator and string behavior -
so have linear vector using store 2d value through class: want print values in reverse ... value (0,0)
occupies bottom left , (max_x,max_y)
occupies top right ... typical cartesian grid. here code:
std::string ss=""; int i=0; (std::vector<real>::reverse_iterator it= vector.rbegin(); it!=vector.rend();++it) { if (linechanger==max_x) { std::cout<<ss<<std::endl; ss=""; linechanger=0; } ss=std::to_string(*it) +"|"+ ss; linechanger++; }
note: if not use string , print directly , fine , order reversed. member functions work in main code use std::fill
fill vector value need (class function call). change few values e.g. @ (0,0)
, (max_x,max_y)
manually. (member functions ) filled 2.38 6x6 =36 sized vector changed. change first value accessed ( last in vector, first in reverse iterator) 3. , run program. output:
2.380000|2.380000|2.380000|2.380000|2.380000|2.380000| 2.380000|2.380000|2.380000|2.380000|2.380000|2.380000| 2.380000|2.380000|2.380000|2.380000|2.380000|2.380000| 2.380000|2.380000|2.380000|2.380000|2.380000|2.380000| 2.380000|2.380000|2.380000|2.380000|2.380000|2.380000|
that whole size of vector, initial std::fill value... wrong? want avoid []
operator .
notice sample output contains 30 values, not 36 values. loop prints string on iteration after contains max_x
values. @ end of loop, last line of values in string variable never printed.
Comments
Post a Comment