我看晚上有些资料是这样用的vector<CString> m_vtpMy;//如果我按顺序存入的时候m_vtpMy.push_back("d");
m_vtpMy.push_back("f");
m_vtpMy.push_back("e");
m_vtpMy.push_back("c");
m_vtpMy.push_back("a");//那么下面两种方法有什么区别
//方法1
for(int i=0;i<m_vtpMy.size();i++)
{
MessageBox(m_vtpMy[i]);
}
//方法2
std::vector<CString>::iterator theIt;
for(theIt = m_vtpMy.begin(); theIt!=m_vtpMy.end(); theIt++)
{
MessageBox(*theIt);
}谢谢解答
m_vtpMy.push_back("f");
m_vtpMy.push_back("e");
m_vtpMy.push_back("c");
m_vtpMy.push_back("a");//那么下面两种方法有什么区别
//方法1
for(int i=0;i<m_vtpMy.size();i++)
{
MessageBox(m_vtpMy[i]);
}
//方法2
std::vector<CString>::iterator theIt;
for(theIt = m_vtpMy.begin(); theIt!=m_vtpMy.end(); theIt++)
{
MessageBox(*theIt);
}谢谢解答
对list,map,set这些容器来说,只能用iterator,不能用i
+1如果用vector,用迭代器访问和下标访问是一样的,因为vector在内存中是连续分配的,如果用list,那就不能用下标了,只能用迭代器访问,因为它是不连续的