C++primer 10.2.1 Sessions

Source: Internet
Author: User

Exercise 10.3

1#include <iostream>2#include <string>3#include <vector>4#include <stack>5#include <algorithm>6#include <numeric>7#include <list>8 9 using namespacestd;Ten  One  A intMain () - { -vector<int> vec{1,2,3,4,5,6,7,8,9,Ten }; the     intval =0; -Auto num =accumulate (Vec.cbegin (), Vec.cend (), Val); -cout << Num <<Endl; -System"Pause"); +     return 0; -}

Exercise 10.4

The last value returned will be lost, but the compiler will not prompt for an error because the type of the third parameter of accumulate determines the type of return value that is used by the addition operator in the function;

Exercise 10.5

If written in char *, a warning is given that the string can be modified, and the string in the example is not allowed to be modified, the better way is to write the const char *;

1#include <iostream>2#include <string>3#include <iostream>4#include <string>5#include <vector>6#include <algorithm>7 using namespacestd;8 9 intMain ()Ten { OneConstChar*S1 ="Good"; AConstChar*S2 =" Boy"; -vector<Const Char*>Roster1, Roster2; - Roster1.push_back (S1); the roster1.push_back (S2); - Roster2.push_back (S1); - roster2.push_back (S2); -  +     BOOLFlag =equal (Roster1.cbegin (), Roster1.cend (), Roster2.cbegin ()); -  +     if(true==flag) Acout <<"Same ..."<<Endl; at     Else -cout <<"Not same ..."<<Endl; -System"Pause"); -     return 0; -}

C++primer 10.2.1 Sessions

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.