I want to iterate over a vector in C++11. I used two different approach for creating a loop. The first one is using auto and the other one is getting elements by index. It is really strange for me and it would be great if someone explains to me that why the output of these two are different.
for (auto tbl = schema.begin();tbl != schema.end(); tbl++)
{
cout << "tbl: " << tbl->getTblName() << tbl->getAry()<<endl;
vector<Column> clm = tbl->getColumns();
for (int i = 0; i < clm.size(); i++)
{
cout << "clm1:" << clm.at(i).getAttrName() << endl;
}
for (auto cl = tbl->getColumns().begin(); cl != tbl->getColumns().end(); cl++)
cout << "clm2:" << cl->getAttrName() << endl;
}
The output is:
tbl: users4
**clm1:uid**
clm1:age
clm1:sex
clm1:occupation
**clm2:P�M** // this is the problem. It only prints random char.
clm2:age
clm2:sex
clm2:occupation
Aucun commentaire:
Enregistrer un commentaire