CString showW,showM;
std::list<CString>::iterator it ;
for(it = findf.fils.begin();it != findf.fils.end();++it){
wcont++;
showW += *it;
showW += "\r\n";
}这段代码中,findf是一个类的对象,fils是这个类的成员变量,std::list<CString> fils;
这里的it只是一个变量,而不是一个指针变量,为什么下面循环中,感觉it像一个数组指针?
希望大家给小弟讲解一下!

解决方案 »

  1.   

    it是list迭代器的对象
    简单说说把,就是可以指向容器中元素的东西,就好像指针那样,但是它不是指针。
    他提供一种方法顺序访问一个聚合对象中各个元素,而又不需要暴露对象的内部表示。
    具体参看C++ Primer的讲解
      

  2.   

    楼上说的对,将iterator理解为指针就行了。另外,遍历不改变iterator值时应尽理使用const_iterator。
      

  3.   

    it是list迭代器的对象,可以理解为指针,指向容器列表中元素,就好像指针那样,但是不同于指针。
    在Vector容器中也用迭代器。 
    //将用户处理后的联动对象添加到“联动设置”对话框的列表中
    int rowNum = m_lstCmbMotion.GetItemCount();
    std::vector<AlertRecTarget>::iterator pIterAlertRec;
    for (pIterAlertRec=recordMTargetSelectdlg.m_alertRecTargets.begin();
     pIterAlertRec!=recordMTargetSelectdlg.m_alertRecTargets.end();
     pIterAlertRec++)
    {
    str.LoadString(IDS_CMBMOTIONTYPE_ALERTREC);
    m_lstCmbMotion.InsertItem(rowNum,str);
    m_lstCmbMotion.SetItemText(rowNum,1,pIterAlertRec->DevName.c_str());
    m_lstCmbMotion.SetItemText(rowNum,2,pIterAlertRec->DevIp.c_str());
    m_lstCmbMotion.SetItemText(rowNum,3,pIterAlertRec->ChannelName.c_str());
    m_lstCmbMotion.SetItemText(rowNum,4,pIterAlertRec->ChannelGuid.c_str());
    rowNum++;
    }
      

  4.   

    在对话框recordMTargetSelectdlg中定义如下的vector列表变量:
    std::vector<AlertRecTarget> m_alertRecTargets;