Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the size() of string returned by iterator

Tags:

c++

visual-c++

vector<string> frame(const vector<string>& v){
   vector<string> ret;
   string::size_type maxlen = width(v);
   string border(maxlen + 4,'*');

   //write the top border
   ret.push_back(border);

  //write each interior row
  for(vector<string>::const_iterator i = v.begin();i != v.end();++i){
     ret.push_back("* " + *i + string(maxlen- (*i.size()),' ') + " *");
  }

  //write the bottom border
  ret.push_back(border);

  return ret;
 }

In the for loop I am getting an error while accessing the size() member function of the string returned by iterator i ----> *i.size();

"class "std::_Vector_const_iterator>>" has no member "size"

like image 236
SacGax Avatar asked Oct 07 '12 14:10

SacGax


1 Answers

(*i).size(). the . operator has higher precedence than *

like image 103
nothrow Avatar answered Oct 04 '22 10:10

nothrow