C + + classes and vectors
C + + has many standard libraries that provide a number of pre-defined functions, such as mathematical calculations, file input/output, text manipulation, etc.
At the same time, C + + contains a lot of Standard Template Library , which contains a lot of software applications and classes, programmers can directly use them.
Standard library: A library that is part of the C + + language, such as cout, is an object in standard library <iostream> that can be used to implement output to the screen
STL a C + + library that contains prototypes of classes that can be used directly.
As Vector is one of the STL classes, it stores data elements in a linear list
Simply put, a class is a description of a job, constructs an object through a class, and implements various tasks in the class through the object of the class.
Example code:
Results:
Demonstration of C + + vectors
Vector has 4 numbers
32 21 92) 45 15
#include <iostream>#include<iomanip>//in order to use SETW#include <vector>//in order to use vectorsusing namespacestd;intmain () {vector<int> vnums;//a vector object that contains integerscout<<"demonstration of C + + vectors \ n"; //four integers are deposited into the vector by the function push_back ()Vnums.push_back ( +); Vnums.push_back ( +); Vnums.push_back ( the); Vnums.push_back ( $); //get the number of integers in a vector by size ()cout <<"Vector has"<< vnums.size () <<"numbers \ n"; //Add two more numbersVnums.push_back ( the); //show the integers contained in the vector for(inti =0; I<vnums.size (); i++) {cout<< SETW (3) <<vnums.at (i); } cin.Get(); return 0;}
"Modern C + + program Design" (US) Barbara Johnston----1