日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

C++primer 10.2.1节练习

發(fā)布時(shí)間:2025/4/9 c/c++ 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++primer 10.2.1节练习 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

練習(xí)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 namespace std; 10 11 12 int main() 13 { 14 vector<int> vec{ 1,2,3,4,5,6,7,8,9,10 }; 15 int val = 0; 16 auto num = accumulate(vec.cbegin(), vec.cend(), val); 17 cout << num << endl; 18 system("pause"); 19 return 0; 20 }

練習(xí)10.4

最后返回的值精度會(huì)丟失,但編譯器不會(huì)提示有錯(cuò)誤,因?yàn)閍ccumulate的第三個(gè)參數(shù)的類型決定了函數(shù)中使用哪個(gè)加法運(yùn)算符一級(jí)返回值的類型;

練習(xí)10.5

如果寫成 char * 會(huì)發(fā)出警告,表示字符串可以修改,而例子中的字符串不允許修改,更好的方法是寫成const char *;?

1 #include<iostream> 2 #include<string> 3 #include <iostream> 4 #include <string> 5 #include <vector> 6 #include <algorithm> 7 using namespace std; 8 9 int main() 10 { 11 const char *s1 = "good"; 12 const char *s2 = "boy"; 13 vector<const char *> roster1, roster2; 14 roster1.push_back(s1); 15 roster1.push_back(s2); 16 roster2.push_back(s1); 17 roster2.push_back(s2); 18 19 bool flag = equal(roster1.cbegin(), roster1.cend(), roster2.cbegin()); 20 21 if (true == flag) 22 cout << "same..." << endl; 23 else 24 cout << "not same..." << endl; 25 system("pause"); 26 return 0; 27 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/wuyinfenghappy/p/7350573.html

總結(jié)

以上是生活随笔為你收集整理的C++primer 10.2.1节练习的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。