Thus after myVec.erase(myVec.begin()) i have the following:
2 3 4 5 5.
What do you get for the ouput with this code:
Code:
#pragma warning( disable : 4786 )
#include<iostream>
#include<vector>
#include<algorithm> //copy()
using namespace std;
int main()
{
vector<int> myVec;
for(int i=1; i<=5; i++)
{
myVec.push_back(i);
}
cout<<"size: "<<myVec.size()<<endl;
copy(myVec.begin(), myVec.end(), ostream_iterator<int>(cout, " "));
cout<<endl<<endl;
myVec.erase(myVec.begin());
cout<<"size: "<<myVec.size()<<endl;
copy(myVec.begin(), myVec.end(), ostream_iterator<int>(cout, " "));
cout<<endl;
return 0;
}
The STL also has a simple queue class:
Code:
#pragma warning( disable : 4786 )
#include<iostream>
#include<queue>
using namespace std;
int main()
{
queue<int> myQ;
for(int i=1; i<=5; i++)
{
myQ.push(i);
}
while(!myQ.empty())
{
cout<<myQ.front()<<" ";
myQ.pop();
}
cout<<endl;
return 0;
}