1

由于在代码上浪费了更多时间,我越来越感到困惑。我只想要迭代器的内容,而不是它的地址。这是我的代码:

Peptides tempPep;
tempPep.set_PEPTIDE("AABF");
std::vector<Peptides>::iterator itPep = std::find_if (this->get_PepList().begin(), this->get_PepList().end(),boost::bind(&Peptides::Peptide_comparison, _1,tempPep)); 
if (itPep != this->get_PepList().end()) 
{

   Spectra tempSp;
   tempSp.set_Charge(1127);
   tempSp.set_Snum(1);
   std::cout << "without iterator "<< this->get_PepList()[0].get_New_S_num() << std::endl; 
   // output -> 0
   std::cout << "with iterator" << itPep->get_New_S_num() <<std::endl;
   //output -> 1129859637
}
4

2 回答 2

2

尝试将您的代码更改为以下内容:

std::vector<Peptides> p = this->get_PepList();
std::vector<Peptides>::iterator itPep = std::find_if (p.begin(),
    p.end(),boost::bind(&Peptides::Peptide_comparison, _1,tempPep)); 
于 2013-05-13T20:18:51.887 回答
1

如果您想要内容,请指向它:*itPep

迭代器重载运*算符并返回数据。(感谢指正,我不知道!)

于 2013-05-13T20:05:44.060 回答