Using a list: push_back, begin, end, size
#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> listObject;
int i;
for(i = 0; i <10; i++)
listObject.push_back(i);
cout << "Size = " << listObject.size() << endl;
cout << "Contents: ";
list<int>::iterator p = listObject.begin();
while(p != listObject.end()) {
cout << *p << " ";
p++;
}
cout << "\n\n";
p = listObject.begin();
while(p != listObject.end()) {
*p = *p + 100;
p++;
}
cout << "Contents modified: ";
p = listObject.begin();
while(p != listObject.end()) {
cout << *p << " ";
p++;
}
return 0;
}
Related examples in the same category