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

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

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

容器的访问元素的成员函数(front,back,下标和at)返回的都是引用

發(fā)布時(shí)間:2024/4/18 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 容器的访问元素的成员函数(front,back,下标和at)返回的都是引用 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?容器的訪問(wèn)元素的成員函數(shù)(front,back,下標(biāo)和at)返回的都是引用,如果我們用auto變量去改變保存這些函數(shù)的返回值,并且希望通過(guò)使用此變量來(lái)改變?cè)氐闹?#xff0c;那么必須記得將變量定義為引用

#include <iostream> #include <string> #include <vector> #include <deque> #include <list> #include <forward_list> #include <string> #include <array> using namespace std; #define LENGTH 10 typedef int TYPE; typedef vector<TYPE> VECTORTYPE; typedef deque<TYPE> DEQUETYPE; typedef list<TYPE> LISTTYPE; typedef forward_list<TYPE> FORWARD_LISTTYPE; typedef array<TYPE,LENGTH> ARRAYTYPE; void print(VECTORTYPE & ); void print(DEQUETYPE & ); void print(LISTTYPE & ); void print(FORWARD_LISTTYPE & ); void print(ARRAYTYPE & ); void print(string &); void pluralize(size_t ,string &); void print(list<string> &); void print(vector<string> &); int main() {vector<int> v_int{1,2,3,4,5,6,7,8,9};deque<int> d_int{1,2,3,4,5,6,7,8,9,0};for(size_t i = 0; i != v_int.size() ; ++i){int &a = v_int[i];a = 1024;}print(v_int);for(size_t j = 0; j != d_int.size() ; ++j){int &a = d_int.at(j);a = 1025;}print(d_int);return 0; } void print(VECTORTYPE &vec) {for(VECTORTYPE::iterator i = vec.begin() ; i != vec.end() ; ++i){ cout << *i << " ";}cout << endl;return ; }void print(DEQUETYPE &vec) {for(DEQUETYPE::iterator i = vec.begin() ; i != vec.end() ; ++i){ cout << *i << " ";}cout << endl;return ; }void print(LISTTYPE &vec) {for(LISTTYPE::iterator i = vec.begin() ; i != vec.end() ; ++i){ cout << *i << " ";}cout << endl;return ; }void print(FORWARD_LISTTYPE &vec) {for(FORWARD_LISTTYPE::iterator i = vec.begin() ; i != vec.end() ; ++i){ cout << *i << " ";}cout << endl;return ; }void print(ARRAYTYPE &vec) {for(ARRAYTYPE::iterator i = vec.begin() ; i != vec.end() ; ++i){ cout << *i << " ";}cout << endl;return ; }void print(string & s_vec) {for(string::iterator i = s_vec.begin(); i != s_vec.end() ; ++i) {cout << *i << " ";}cout << endl; } void pluralize(size_t cnt,string &word) {if(cnt > 1)word.push_back('s');//equal to word += 's' }void print(vector<string> & s_vec) {for(auto &i :s_vec)cout << i << " ";cout << endl; } void print(list<string> & s_list) {for(auto & i: s_list)cout << i << " ";cout << endl; }

?

總結(jié)

以上是生活随笔為你收集整理的容器的访问元素的成员函数(front,back,下标和at)返回的都是引用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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