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