0% found this document useful (0 votes)
12 views

Advance Programming in C++

Advance programming in C++
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Advance Programming in C++

Advance programming in C++
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

std::vector < int >

v1;
v1.push_back (10);

= it declares vector (v1) and pushes back value 10

vector < int >v1 (10, 3);


v1push_back (3);
cout << v1.capacity () << v1.size () << end1;

= it creates vector (v1) with the final size of eleven integers of value 3

std::vector < int >


v1;
for (int i = 0; i < 10; i++)
v1.push_back (i);
std: : vector <int>
v2 (v1.begin () + 2, v1.end () - 2);

= it creates vector (v2) with the final size of six integers


= it creates vector (v1) with the final size of ten integers

std::vector < int >


v1;
for (int i = 0; i < 10; i++)
v1.push_back (i);
v1.resize (4);
std::vector <int>
v2 (v1.begin () +1. v1.end () - 1);

= it creates vector (v2) with the final size of two integers


= it creates vector (v1) with the final size of four integers

std::vector < int >


v1;
for (int i = 0; i < 10; i++)
v1.push_back (i);
v1.resize (4);
std::vector <int>
v2 (v1.begin () +1. v1.end () - 1);

=it declares vector (v1) with six not equal values (0, 1)

std::vector < int >


v1;
for(int i = 10; i> 0; i--)
v1.push_back (i);
v1.erase (v1.begin (), v1.end () - 3);

= it creates vector (v1) with the final size of three integers

int t[] = {1,2,3,4,5,};


std::vector < int >
v1 (t, t + 5);
std::vector < int >
v2 (v1);
v1.resize (10);
v2.reserve (10);
= it creates vector (v2) with the final size of five integers
= it creates vector (v1) with the final size of ten integers

vector < int >v1;


deque < int >d1;
v1.push_back (1);
v1.push_front (2);
d1.push_back (3);
d1.push_front (4);

= it doesn't compile because there is no push_front method in the vector class

vector < int >v1;


deque < int >d1;
v1.push_back (1);
d1.push_back (3);
v1.empty ();
d1.empty ();

= it creates deque (d1) with the final size of 1


= it creates vector (v1) with the final size of 1

vector < int >v1;


deque < int >d1;
v1.push_back (1);
d1.push_back (3);
v1.empty ();
d1.empty ();

= it creates deque (d1) with the final size of 0


= it creates vector (v1) with the final size of 0

You might also like