Post by Kei-Lin on Apr 30, 2008 21:54:59 GMT -5
I came up with another new code...
#include <stdio.h>
#include <iostream.h>
#include <vector>
void main(){
vector<int> myVector;
vector<int>::iterator Iter;
if( myVector.empty() )
{
cout << endl << "The vector is currently empty.";
}
cout << endl;
cout << "Adding 10 to the end of the vector." << endl;
myVector.push_back(10);
cout << "Adding 20 to the end of the vector." << endl;
myVector.push_back(20);
cout << "Adding 30 to the end of the vector." << endl;
myVector.push_back(30);
cout << "Adding 40 to the end of the vector." << endl;
myVector.push_back(40);
cout << "Adding 1 to the end of the vector." << endl;
myVector.push_back(1);
cout << "Adding 2 to the end of the vector." << endl;
myVector.push_back(2);
cout << "Adding 3 to the end of the vector." << endl;
myVector.push_back(3);
cout << "Adding 4 to the end of the vector." << endl;
myVector.push_back(4);
cout << "Adding 5 to the end of the vector." << endl;
myVector.push_back(5);
cout << endl << "Current vector size = " << myVector.size() << endl;
int atTheEnd;
atTheEnd = myVector.back();
cout << "The last element, " << atTheEnd << ", is being removed." << endl << endl;
myVector.pop_back();
cout << "Current vector size: " << myVector.size() << endl;
cout << "myVector =";
for (Iter = myVector.begin(); Iter != myVector.end(); Iter++ )
{
cout << " " << *Iter;
}
cout << endl;
cout << endl;
if( !myVector.empty() )
{
myVector.clear();
}
if( myVector.empty() )
{
cout << "The vector is now empty again." << endl;
}
cout << endl;
system("PAUSE");
}
Yeah, yeah, I know, it's not very practical. But it's still cool!
#include <stdio.h>
#include <iostream.h>
#include <vector>
void main(){
vector<int> myVector;
vector<int>::iterator Iter;
if( myVector.empty() )
{
cout << endl << "The vector is currently empty.";
}
cout << endl;
cout << "Adding 10 to the end of the vector." << endl;
myVector.push_back(10);
cout << "Adding 20 to the end of the vector." << endl;
myVector.push_back(20);
cout << "Adding 30 to the end of the vector." << endl;
myVector.push_back(30);
cout << "Adding 40 to the end of the vector." << endl;
myVector.push_back(40);
cout << "Adding 1 to the end of the vector." << endl;
myVector.push_back(1);
cout << "Adding 2 to the end of the vector." << endl;
myVector.push_back(2);
cout << "Adding 3 to the end of the vector." << endl;
myVector.push_back(3);
cout << "Adding 4 to the end of the vector." << endl;
myVector.push_back(4);
cout << "Adding 5 to the end of the vector." << endl;
myVector.push_back(5);
cout << endl << "Current vector size = " << myVector.size() << endl;
int atTheEnd;
atTheEnd = myVector.back();
cout << "The last element, " << atTheEnd << ", is being removed." << endl << endl;
myVector.pop_back();
cout << "Current vector size: " << myVector.size() << endl;
cout << "myVector =";
for (Iter = myVector.begin(); Iter != myVector.end(); Iter++ )
{
cout << " " << *Iter;
}
cout << endl;
cout << endl;
if( !myVector.empty() )
{
myVector.clear();
}
if( myVector.empty() )
{
cout << "The vector is now empty again." << endl;
}
cout << endl;
system("PAUSE");
}
Yeah, yeah, I know, it's not very practical. But it's still cool!