replace 的用法
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/08 15:23:10
replace 的用法
eplace是STL 算法中的一种,其用法如下:
Examines each element in a range and replaces it if it matches a specified value.
template
void replace(
ForwardIterator _First,
ForwardIterator _Last,
const Type& _OldVal,
const Type& _NewVal
);
Parameters
_First
A forward iterator pointing to the position of the first element in the range from which elements are being replaced.
_Last
A forward iterator pointing to the position one past the final element in the range from which elements are being replaced.
_OldVal
The old value of the elements being replaced.
_NewVal
The new value being assigned to the elements with the old value.
Remarks
The range referenced must be valid; all pointers must be dereferenceable and within the sequence the last position is reachable from the first by incrementation.
The order of the elements not replaced remains stable.
The operator== used to determine the equality between elements must impose an equivalence relation between its operands.
The complexity is linear; there are (_Last – _First) comparisons for equality and at most (_Last – _First) assignments of new values.
Example
Copy Code
// alg_replace.cpp
// compile with: /EHsc
#include
#include
#include
int main( ) {
using namespace std;
vector v1;
vector ::iterator Iter1;
int i;
for ( i = 0 ; i
Examines each element in a range and replaces it if it matches a specified value.
template
void replace(
ForwardIterator _First,
ForwardIterator _Last,
const Type& _OldVal,
const Type& _NewVal
);
Parameters
_First
A forward iterator pointing to the position of the first element in the range from which elements are being replaced.
_Last
A forward iterator pointing to the position one past the final element in the range from which elements are being replaced.
_OldVal
The old value of the elements being replaced.
_NewVal
The new value being assigned to the elements with the old value.
Remarks
The range referenced must be valid; all pointers must be dereferenceable and within the sequence the last position is reachable from the first by incrementation.
The order of the elements not replaced remains stable.
The operator== used to determine the equality between elements must impose an equivalence relation between its operands.
The complexity is linear; there are (_Last – _First) comparisons for equality and at most (_Last – _First) assignments of new values.
Example
Copy Code
// alg_replace.cpp
// compile with: /EHsc
#include
#include
#include
int main( ) {
using namespace std;
vector v1;
vector ::iterator Iter1;
int i;
for ( i = 0 ; i
substitute的用法,与replace的区别
英语exchange 与 replace 的用法差别
replace 和 instead of 的用法
substitute/replace/exchange 用法辨析
vb 中 replace 与 replace$ 的区别
请教一下四个词的区别用法,displace replace supplant supersede,要例句,
Replace(" ",
replace
英语两个短语的区别,replace with replace as
请问replace by和replace with的区别是什么?
displace和replace的区别
replace和substitute的问题