std::replace函数
需包含头文件#include <algorithm>
template <class ForwardIterator, class T>
void replace (ForwardIterator first, ForwardIterator last,
const T& old_value, const T& new_value);
实现:
template <class ForwardIterator, class T>
void replace (ForwardIterator first, ForwardIterator last,
const T& old_value, const T& new_value)
{
while (first!=last) {
if (*first == old_value) *first=new_value;
++first;
}
}
参考示例:
// replace algorithm example
#include <iostream> // std::cout
#include <algorithm> // std::replace
#include <vector> // std::vector int main () {
int myints[] = { , , , , , , , };
std::vector<int> myvector (myints, myints+); // 10 20 30 30 20 10 10 20 std::replace (myvector.begin(), myvector.end(), , ); // 10 99 30 30 99 10 10 99 std::cout << "myvector contains:";
for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n'; return ;
}
输出结果:

std::replace函数的更多相关文章
- 【javascript杂谈】你所不知道的replace函数
前言 最近在做面试题的时候总会用到这个函数,这个函数总是和正则表达式联系到一起,并且效果很是不错,总能很简单出色的完成字符串的实际问题,大家肯定都会使用这个函数,像我一样的初学者可能对这个函数的了解还 ...
- MySQL replace函数替换字符串语句的用法(mysql字符串替换)
MySQL replace函数我们经常用到,下面就为您详细介绍MySQL replace函数的用法,希望对您学习MySQL replace函数方面能有所启迪. 最近在研究CMS,在数据转换的时候需要用 ...
- oracle replace函数
replace 函数用法如下: replace('将要更改的字符串','被替换掉的字符串','替换字符串') 例如: select t.dqsj,replace(t.dqsj,'16:40','16: ...
- 笔记:js的replace函数
replace函数 js的replace函数与c#的有一个不同,js的只替换第一个字符 例如,var a=',1,2' var b=a.replace(',','') 结果b='1,2'(ps:这是一 ...
- Sql Server REPLACE函数的使用;SQL中 patindex函数的用法
Sql Server REPLACE函数的使用 REPLACE用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法REPLACE ( ''string_replace1'' ...
- Oracle 中的replace函数的应用
replace 函数用法如下: replace('将要更改的字符串','被替换掉的字符串','替换字符串') oracle 中chr()函数 CHR() --将ASCII码转换为字符 语法CHR(nu ...
- 合并多行查询数据到一行:使用自连接、FOR XML PATH('')、STUFF或REPLACE函数 (转)
转自: http://www.cnblogs.com/aolin/archive/2011/04/12/2014122.html 示例表 tb 数据如下 id value—————1 aa1 bb2 ...
- javascript中通过replace函数搜索和替换指定字符串
javascript中我们可以通过replace函数替换部分字符串为指定字符串,本文展示了replace的详细用法,并且通过范例演示了如何进行部分替换.完整替换和不区分大小写替换. javascrip ...
- Oracle replace函数使用
需求是要修改Oracle某列表中把这一列中全部的100换成200: update b_nodes a set a.childs=replace((select childs from b_nodes ...
随机推荐
- 【极大化剪枝】Power Hungry Cows-C++【没有用A*!】【超级简单!】
Description小KITTY想要快速计算整数P的幂 (1 <= P <=10,000),它们需要你的帮助.因为计算极大数的幂,所以它们同一时间仅能使用2个存储器,每个存储器可记录某个 ...
- checkbox选中的行数
$('[name=roomcheck]').each(function(){ if($(this).prop("checked")==true){ alert(this.id);/ ...
- 【csp模拟赛3】bridge.cpp--矩阵加速递推
题目描述 穿越了森林,前方有一座独木桥,连接着过往和未来(连接着上一题和下一题...). 这座桥无限长. 小 Q 在独木桥上彷徨了.他知道,他只剩下了 N 秒的时间,每一秒的时间里,他会向 左或向右移 ...
- GAN生成式对抗网络(四)——SRGAN超高分辨率图片重构
论文pdf 地址:https://arxiv.org/pdf/1609.04802v1.pdf 我的实际效果 清晰度距离我的期待有距离. 颜色上面存在差距. 解决想法 增加一个颜色判别器.将颜色值反馈 ...
- Cats and Fish HihoCoder - 1631
Cats and Fish HihoCoder - 1631 题意: 有一些猫和一些鱼,每只猫有固定的吃鱼速度,吃的快的猫优先选择吃鱼,问在x秒时有多少完整的鱼和有多少猫正在吃鱼? 题解: 模拟一下. ...
- javascript监听浏览器前进后退
window.addEventListener("popstate", function () { backStatus=true; return; })
- nginx 部署php
一:nginx安装: yum install nginx 安装完成即可,在/usr/sbin/目录下是nginx命令所在目录,在/etc/nginx/目录下是nginx所有的配置文件,用于配置ngin ...
- Hadoop Shell命令字典
转载自:https://www.aboutyun.com//forum.php/?mod=viewthread&tid=6983&extra=page%3D1&page=1&a ...
- struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []
使用struts的都知道,下面使用通配符定义的方式很常见,并且使用也很方便: <action name="Crud_*" class="example.Crud&q ...
- 冲刺总结——Day7
[今日进展] 代码整合 码云链接:https://gitee.com/jxxydwt1999/20175215-java/tree/master/GoldPoint 功能测试 注册 登录 运行 [燃尽 ...