早教吧作业答案频道 -->其他-->
简明扼要的介绍下replacecopy()函数的用法.
题目详情
简明扼要的介绍下replace_copy()函数的用法.
▼优质解答
答案和解析
是STL里面的replace_copy()吗?如果是,那么这个函数的意思就是把一个区间(range)的数据拷贝到另一个区间里;而且copy的同时,作replace(替换).
比如:
#include
#include
#include
using namespace std;
int main () {
int myints[] = { 10, 20, 30, 30, 20, 10, 10, 20 };
vector myvector (8);
replace_copy (myints, myints+8, myvector.begin(), 20, 99);
for (vector::iterator it=myvector.begin(); it!=myvector.end(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}
输出结果是:
10 99 30 30 99 10 10 99
就是把myints中的数据copy到myvector中,同时把myints中所有值=20的元素替换为99.
比如:
#include
#include
#include
using namespace std;
int main () {
int myints[] = { 10, 20, 30, 30, 20, 10, 10, 20 };
vector
replace_copy (myints, myints+8, myvector.begin(), 20, 99);
for (vector
cout << ' ' << *it;
cout << '\n';
return 0;
}
输出结果是:
10 99 30 30 99 10 10 99
就是把myints中的数据copy到myvector中,同时把myints中所有值=20的元素替换为99.
看了 简明扼要的介绍下replac...的网友还看了以下:
f(x)=2+sinx/1+x^2是什么函数A有界函数B周期函数C奇数函数 2020-04-26 …
如表是函数值y随自变量x变化的一组数据,由此判断它最可能的函数模型A一次函数模型B二次函数模型C指 2020-05-14 …
二次函数y=ax²+bx+c的图像如图所示,若M=4a+2b+c,N=a-b+c,P=4a+2b, 2020-05-16 …
文中( 5 )处正确的答案是( )。 A.单调递增函数B.单调递减函数C.对数函数D.指数函数 2020-05-26 …
某商品供给量Q对价格P的函数关系为Q=Q(P)=a+b*c的p次方(c≠1)已知当P=2时,Q=3 2020-06-07 …
已知c>0,且c≠1,设p:函数y=cx在R上单调递减;q:函数f(x)=x2-2cx+1在(12 2020-06-16 …
已知c>0,设命题p:函数y=cx为减函数;命题q:当x∈[12,2]时,函数f(x)=x+1x> 2020-06-20 …
设点P是函数f(x)=cos (wx+ A)的图像C的一个对称中心距离,若点P到图像C的对称轴的最 2020-06-27 …
设p:指数函数y=c^x在R上是减函数,那p的否定中c的取值范围是(1)c>1,还是(2)c=1设 2020-08-01 …
已知f(x)=㏒a(x+1)(a>0,且a≠1),若x∈(-1,0)时,f(x)<0,则f(x)是A 2020-11-28 …