C++ VectorTest3

来源:互联网 发布:ubuntu修改机器名 编辑:程序博客网 时间:2024/05/02 22:04
#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
using std::vector<char>::iterator;




int main()
{


vector<char> CONTAINER;
CONTAINER.push_back('A');
CONTAINER.push_back('B');
CONTAINER.push_back('C');
CONTAINER.push_back('D');
for (int i = 0;i < 4 ; i++)
cout<<CONTAINER[i]<<endl;
iterator p =  CONTAINER.begin();
cout<<"The Third entry is "<<CONTAINER[2]<<endl;
cout<<"The Third entry is "<<p[2]<<endl;
cout<<"The Third entry is "<<*(p+2)<<endl;
cout<<"Back to container[0].\n";
p = CONTAINER.begin();
cout<<"Which has value "<<*p<<endl;
cout<<"Two steps forward and one step back:\n";
p++;
cout<<*p<<endl;
p++;
cout<<*p<<endl;
p--;
cout<<*p<<endl;
return 0;
for (p = CONTAINER.begin(); p!= CONTAINER.end(); p++)
cout<<*p<<" ";
cout<<endl;


cout<<"Setting entries to 0:\n";
for (p = CONTAINER.begin(); p!= CONTAINER.end(); p++)
*p = 0;
cout<<"CONTAINER now contains:\n";
for (p = CONTAINER.begin(); p!= CONTAINER.end(); p++)
cout<<*p<<" ";
cout<<endl;




return 0;


}