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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

STL 之replace,replace_if,replace_copy,replace_copy_if

發(fā)布時間:2024/4/11 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 STL 之replace,replace_if,replace_copy,replace_copy_if 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
作用:用一個新值替換指定區(qū)間內(nèi)所有的指定元素。

聲明:

  • #include?<algorithm>??
  • template?<class?forwardItr,class?Type>??
  • void?replace(forwardItr?first,?forwardItr?last,const?Type&?oldValue?const?Type&?newValue);??
  • ??
  • template?<class?forwardItr,?class?unaryPredicate,class?Type>??
  • void?replace_if(forwardItr?first,?forwardItr?last,?unaryPredicate?op,const?Type&?newValue);??
  • ??
  • template?<class?inputItr,class?outputItr,class?Type>??
  • outputItr?replace_copy(inputItr?first1,?inputItr?last1,?outputItr?destFirst,const?Type&?oldValue,?const?Type&?newValue);??
  • ??
  • template?<class?inputItr,class?outputItr,?class?unaryPredicate>??
  • outputItr?replace_copy_if(inputItr?first1,?inputItr?last1,?outputItr?destFirst,?unaryPredicate?op,const?Type&?newValue);??

  • 示例代碼:

  • #include?<iostream>??
  • #include?<list>??
  • ??
  • #include?<string>??
  • #include?<numeric>??
  • #include?<iterator>??
  • #include?<vector>??
  • #include?<functional>??
  • ??
  • #include?<algorithm>??
  • ??
  • using?namespace?std;??
  • ??
  • bool?lessThanEqual50(int?num)?{??
  • ????return?(num?<=?50);??
  • }??
  • ??
  • int?main()?{??
  • ????char?cList[10]?=?{'A','a','A','B','A','c','D','e','F','A'};??
  • ????vector<char>?charList(cList,cList+10);??
  • ????ostream_iterator<char>?screen(cout,?"?");??
  • ??
  • ????cout?<<?"charList:"?<<?endl;??
  • ????copy(charList.begin(),charList.end(),screen);??
  • ????cout?<<?endl;??
  • ????//?replace??
  • ????//?將容器中的A替換為Z??
  • ????replace(charList.begin(),charList.end(),'A','Z');??
  • ????cout?<<?"charList.replace?A?->?Z:"?<<?endl;??
  • ????copy(charList.begin(),charList.end(),screen);??
  • ????cout?<<?endl;??
  • ????//?replace_if??
  • ????//?將所有的大寫字母替換為*??
  • ????replace_if(charList.begin(),charList.end(),isupper,'*');??
  • ????cout?<<?"charList.replace_if?Upper->*"?<<?endl;??
  • ????copy(charList.begin(),charList.end(),screen);??
  • ????cout?<<?endl;??
  • ??
  • ????int?listi[10]?=?{12,34,56,21,34,78,34,55,12,25};??
  • ????vector<int>?intList(listi,listi+10);??
  • ????ostream_iterator<int>?screenInt(cout,?"?");??
  • ????cout?<<?"intList:"?<<?endl;??
  • ????copy(intList.begin(),intList.end(),screenInt);??
  • ????cout?<<?endl;??
  • ??
  • ????vector<int>?temp1(10);??
  • ????//?將intList中34全部替換為0,并輸出到temp1中,不改變intList??
  • ????replace_copy(intList.begin(),intList.end(),temp1.begin(),34,0);??
  • ????cout?<<?"intList.replace_copy:"?<<?endl;??
  • ????copy(intList.begin(),intList.end(),screenInt);??
  • ????cout?<<?endl;??
  • ????cout?<<?"temp1:"?<<?endl;??
  • ????copy(temp1.begin(),temp1.end(),screenInt);??
  • ????cout?<<?endl;??
  • ??
  • ????vector<int>?temp2(10);??
  • ????//?將intList中小于50的全部替換為50,并輸出到temp2中,不改變intList??
  • ????replace_copy_if(intList.begin(),intList.end(),temp2.begin(),lessThanEqual50,50);??
  • ????cout?<<?"intList.replace_copy_if:"?<<?endl;??
  • ????copy(intList.begin(),intList.end(),screenInt);??
  • ????cout?<<?endl;??
  • ????cout?<<?"temp2:"?<<?endl;??
  • ????copy(temp2.begin(),temp2.end(),screenInt);??
  • ????cout?<<?endl;??
  • ??
  • ????return?0;??
  • }??

  • 運(yùn)行結(jié)果:

    charList:
    A a A B A c D e F A
    charList.replace A -> Z:
    Z a Z B Z c D e F Z
    charList.replace_if Upper->*
    * a * * * c * e * *
    intList:
    12 34 56 21 34 78 34 55 12 25
    intList.replace_copy:
    12 34 56 21 34 78 34 55 12 25
    temp1:
    12 0 56 21 0 78 0 55 12 25
    intList.replace_copy_if:
    12 34 56 21 34 78 34 55 12 25
    temp2:
    50 50 56 50 50 78 50 55 50 50

    總結(jié)

    以上是生活随笔為你收集整理的STL 之replace,replace_if,replace_copy,replace_copy_if的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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

    主站蜘蛛池模板: 亚洲色图偷 | 国产精选一区 | 福利在线一区二区 | 亚洲国产成人va在线观看天堂 | 久久精品欧美视频 | 天天拍夜夜爽 | 久久黄色 | 69精品人妻一区二区三区 | 亚洲区一区二区 | a级片免费网站 | 亚洲视频 一区 | 免费黄毛片 | 国产免费无遮挡吸奶头视频 | 东方伊甸园av在线 | 黄色在线观看网址 | 日本在线第一页 | 婷婷开心激情 | 麻豆影视在线免费观看 | 无码少妇一级AV片在线观看 | 欧美乱码精品 | 4438x全国最大成人网 | 丰满人妻妇伦又伦精品国产 | 99re视频这里只有精品 | 毛片h | 亚洲成人网页 | 在线中出 | 98久久 | 在线不卡av电影 | 成年网站在线播放 | 亚洲国产精品久 | 国产女主播喷水高潮网红在线 | 夜色成人 | 国产91av在线播放 | 久久青青草原亚洲av无码麻豆 | 免费观看一级黄色片 | 久久午夜夜伦鲁鲁片无码免费 | 日韩aⅴ片 | 日本不卡一区二区三区 | 国产美女无遮挡永久免费 | 欧美日韩国产中文 | 亚洲精品一区在线观看 | 国产一级片a | 亚洲va韩国va欧美va | 成人免费不卡视频 | 波多野结衣电影在线播放 | 国产在线高潮 | 国产农村妇女精品 | 久草色视频 | av午夜天堂 | 久久免费视频一区二区 | 双性尿奴穿贞c带憋尿 | 天堂网av在线播放 | 日本亚洲欧美在线 | 狠狠人妻久久久久久综合 | 伊人视频| 毛片无遮挡高清免费观看 | 欧美日韩亚洲精品内裤 | a级一片 | 欧美伦理一区二区三区 | 色诱av手机版 | 亚洲男女视频 | 日韩高清影院 | www.亚洲精品 | 亚州av| 伊人久久综合影院 | 女人床技48动态图 | 极品美女被c | 久久亚洲精华国产精华液 | 日韩成人在线观看视频 | 欧美三日本三级少妇99 | www.色在线 | 亚洲国产影视 | 一二级毛片 | 日韩精品在线电影 | 欧洲美熟女乱又伦 | 成人在线观看免费爱爱 | 成人免费aaa | 成片免费观看 | 久久国产精品综合 | 日本精品一区二区视频 | 国产精品久久久久久久久久免费看 | 色视频免费在线观看 | 韩国日本在线 | 九色视频91 | 97在线影院 | 五月涩 | 亚洲女人在线 | 日韩欧美在线中文字幕 | 久久免费小视频 | 中文字幕一区二区在线观看 | 台湾swag在线观看 | 在线成人日韩 | 好吊操av | 亚洲石原莉奈一区二区在线观看 | 五月视频| 91伦理视频 | 最新日韩在线 | 人人干人人做 | 欧美日本韩国一区二区三区 |