Inhaltsverzeichnis

replace()

#include <algorithm>

void replace (For first, For last, T alterwert, T neuerwert) 
void replace (Exec pol, For first, For last, T alterwert, T neuerwert) 
 
In ranges::replace (Range r, T alterwert, T neuerwert, Proj proj = {}) 
In ranges::replace (In first, In last, T alterwert, T neuerwert, Proj proj = {}) 

Ersetzt im Bereich [first,last) alle Elemente e mit proj(e) == alterwert durch neuerwert.

Parameter

first Anfang des Bereiches
last Ende des Bereiches
alterwert zu ersetzender Wert
neuerwert zuzuweisender Wert
proj einstelliger Funktor (Vorgabe = std::identity)
pol parallele Ausführungsart

Ergebnis

Rückgabewert: keiner bzw. last.

Siehe auch

replace_copy(), replace_copy_if(), replace_if().

Beispiel

replace.cpp
#include <algorithm>
#include <string>
#include <iostream>
 
int main()
{
  std::string s = "Harro, Wert";
  std::cout << s << '\n';
 
  std::replace(begin(s), end(s), 'r', 'l');
 
  std::cout << s << '\n';
}