"Modern C + + program Design" (US) Barbara Johnston----1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.