Standard Template Library Vector на C++


#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL,"Rus");
std::vector<int> first;
first.assign (4,50);
std::vector<int> second (3,40);
second.swap(first);
for (std::vector<int>::iterator it = second.begin() ; it != second.end(); ++it)
{
std::cout << ' ' << *it;
}
cout <<endl;
std::vector<int> my_vector;
std::vector<int>::iterator it;
it = my_vector.begin();
it = my_vector.insert (it , 70);
my_vector.push_back(47);
my_vector.pop_back();
my_vector.push_back(10);
my_vector.push_back(15);
my_vector.push_back(20);
my_vector.push_back(7);
my_vector.erase(my_vector.begin()+2); // удаление 3 элемента
cout<<"Количество элементов "<<my_vector.size()<<endl;
for (std::vector<int>::iterator it = my_vector.begin() ; it != my_vector.end(); ++it)
{
std::cout << ' ' << *it;
}
cout <<endl;
for (std::vector<int>::reverse_iterator rit = my_vector.rbegin() ; rit != my_vector.rend(); ++rit)
{
std::cout << ' ' << *rit;
}
cout <<endl;
my_vector.clear();
if (my_vector.empty())
{
cout<<"Empty"<<endl;
}
system("pause");
return 0;
}

Результат работы программы Vector на C++:

C++ STL Vector

Leave a Reply

Ваш e-mail не будет опубликован.