日韩性视频-久久久蜜桃-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)容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 女人下面流白浆的视频 | 亚洲熟女少妇一区二区 | 国产精品免费看片 | 欧美性在线视频 | 一区二区三区日韩视频 | 国产裸体网站 | 久久美女视频 | 免费黄色小视频网站 | 午夜影视网 | 最近中文字幕一区二区 | 成人毛片在线视频 | 色爱亚洲 | 成年免费在线观看 | 欧美久久综合网 | 亚洲午夜精品久久 | 日本无遮挡边做边爱边摸 | 一区二区免费在线观看 | 日韩精品在线免费 | 日b影院| av片在线观看网站 | 天天干夜夜爽 | 一级黄色录相 | www.av88 | 国产无套精品一区二区 | 日本免费电影一区二区三区 | 天天操人人射 | 国产乱子伦精品视频 | 中文字幕久久精品 | av中亚 | 黄片毛片av | 污网站免费观看 | 噜噜噜久久久 | 欧美va在线观看 | 国产精品久久久久久久久久久久久久 | 毛片网站免费观看 | 99福利视频导航 | 91免费在线视频 | 久久精品电影网 | 香蕉久久久久久 | 日本激情影院 | 香蕉视频在线视频 | 91精品婷婷国产综合久久蝌蚪 | 色悠久久久| 欧美人人爽 | 男女做爰真人视频直播 | 清冷学长被爆c躁到高潮失禁 | 亚洲国产97在线精品一区 | 色成人综合网 | 国产精品一区电影 | 男女性网站| 天天干夜夜添 | 床戏高潮做进去大尺度视频网站 | 欧美精品一区二区三区久久久 | 欧美精品www | 99爱精品 | 日本黄色中文字幕 | 日韩精品在线一区 | exo妈妈mv在线播放免费 | 国产视频手机在线观看 | 91大神小宝寻花在线观看 | 美女黄色大片 | 美女一级视频 | xxxx国产| 日韩一区二区a片免费观看 伊人网综合在线 | 综合在线观看 | 亚洲精品手机在线 | 亚洲第一在线视频 | 黄色一级片在线播放 | 美女视频黄频视频大全 | 在线观看成人免费视频 | 欧美区一区 | 亚洲网色| 国产做受高潮 | 亚洲成人网在线播放 | 成人在线观看免费视频 | 99reav| 老女人综合网 | 亚洲无限码 | 国产精品偷伦视频免费看 | 天天插夜夜爽 | 日韩一区在线观看视频 | 国产精品无码免费专区午夜 | 国产成人愉拍精品久久 | 国产成人精品在线 | 奇米色综合 | 蜜桃视频一区二区三区在线观看 | 国产一区二区网址 | 羞羞动漫免费观看 | 黄色在线观看网站 | 69一区二区| 亚洲天堂免费在线观看视频 | 中文字幕在线观看第二页 | 69xx免费视频| 免费av网站在线 | 中文字幕中文字幕 | 日韩视频一二三区 | 91精品啪在线观看国产 | 午夜精品福利影院 | 国产成人91精品 |