SacGax
SacGax

Reputation: 157

get the size() of string returned by iterator

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"

Upvotes: 5

Views: 3828

Answers (1)

nothrow
nothrow

Reputation: 16168

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

Upvotes: 9

Related Questions