VECTORS USING ITERATORS
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
vector<string>ammunition;
ammunition.push_back("launcher");//push_back() add member to vector
ammunition.push_back("tank");
ammunition.push_back("missile");
cout<<"the war is started and the ammunitions tha we have "<<endl;
for(int x=0;x<ammunition.size();x++){
cout<<x<<" = "<<ammunition[x]<<endl;
}
cout<<"during war we captured enemys jeep so now our inventory is = "<<endl;
ammunition.push_back("jeep");
for(int x=0;x<ammunition.size();x++){
cout<<x<<" = "<<ammunition[x]<<endl;
}
cout<<"during the mission at enemy frontline our jeep was destroyed so our ammunition now is = "<<endl;
ammunition.pop_back();//pop_back() delete last element of array
for(int x=0;x<ammunition.size();x++){
cout<<x<<" = "<<ammunition[x]<<endl;
}
cout<<endl<<"due to mutiny within the empire our army lost the battle so our inventory now = "<<endl;
ammunition.clear();//clear all vector
for(int x=0;x<ammunition.size();x++){
cout<<x<<" = "<<ammunition[x];
}
if(ammunition.empty()){
cout<<'0'<<endl;
cout<<"our all weapons are captured by our enemy "<<endl;
}
else{
cout<<"thanks that we have some weapons left"<<endl;
}
}
EmoticonEmoticon