#include <iostream>
#include <vector>
using namespace std;
void showMyVector(const vector<int>& v);
int main()
{
vector<int> myVector;
cout << "Start with nothing" << endl;
showMyVector(myVector);
cout << "Insert something" << endl;
myVector.push_back(0);
myVector.push_back(1);
myVector.push_back(2);
myVector.push_back(3);
myVector.push_back(4);
myVector.push_back(5);
myVector.insert(myVector.begin()+2, 9);
myVector.insert(myVector.end()-1, 10);
myVector.pop_back();
showMyVector(myVector);
cout << "Clear" << endl;
myVector.clear();
showMyVector(myVector);
return 0;
}
void showMyVector(const vector<int>& v){
cout << "myVector.empty: " << v.empty() << endl;
cout << "myVector.size(): " << v.size() << endl;
for(unsigned i = 0; i < v.size(); i++){
cout << v[i] << endl;
}
cout << endl;
}
Sunday, October 2, 2011
STL vector of C++
example:
標籤:
exercise
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment