5
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;
 }

在 for 循环中,访问迭代器 i ----> *i.size(); 返回的字符串的 size() 成员函数时出现错误

"类 "std::_Vector_const_iterator>>" 没有成员 "size"

4

1 回答 1

9

(*i).size(). 运算符的.优先级高于*

于 2012-10-07T14:44:07.970 回答