#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
cout<<"Enter a list of positive number.\n"
<<"Place a negative number at the end.\n";
int next;
cin>>next;
while (next > 0)
{
v.push_back(next);
cout<<next<<" added. ";
cout<<"v.size() = "<<v.size() <<endl;
cin>>next;
}
cout<<"You entered:\n";
for (unsigned int i = 0;i < v.size(); i++ )
{
cout<<v[i]<<" ";
}
cout<<endl;
vector<int> v2(10);
cout<<"v2 size is "<<v2.size()<<endl;
v2.resize(7);
for (unsigned int j = 0;j < v2.size(); j++ )
{
cout<<v2[j]<<" ";
}
cout<<"\ncapacity is ";
cout<<v2.capacity()<<endl;
v2.reserve(32);
cout<<"\n reserve(32) capacity is "<<v2.capacity()<<endl;
return 0;
}
#include <vector>
using namespace std;
int main()
{
vector<int> v;
cout<<"Enter a list of positive number.\n"
<<"Place a negative number at the end.\n";
int next;
cin>>next;
while (next > 0)
{
v.push_back(next);
cout<<next<<" added. ";
cout<<"v.size() = "<<v.size() <<endl;
cin>>next;
}
cout<<"You entered:\n";
for (unsigned int i = 0;i < v.size(); i++ )
{
cout<<v[i]<<" ";
}
cout<<endl;
vector<int> v2(10);
cout<<"v2 size is "<<v2.size()<<endl;
v2.resize(7);
for (unsigned int j = 0;j < v2.size(); j++ )
{
cout<<v2[j]<<" ";
}
cout<<"\ncapacity is ";
cout<<v2.capacity()<<endl;
v2.reserve(32);
cout<<"\n reserve(32) capacity is "<<v2.capacity()<<endl;
return 0;
}