Use replace_copy to replace spaces with colons : replace_copy « STL Algorithms Modifying sequence operations « C++ Tutorial






#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
   
int main()
{
  char str[] = "This is a test.";
  vector<char> v, v2(30);
  unsigned int i;
   
  for(i=0; str[i]; i++) v.push_back(str[i]);
   
  cout << "Input sequence:\n";
  for(i=0; i<v.size(); i++) cout << v[i];
  cout << endl;
   
  // replace spaces with colons
  replace_copy(v.begin(), v.end(), v2.begin(), ' ', ':');
   
   
  cout << "Result after replacing spaces with colons:\n";
  for(i=0; i<v2.size(); i++) cout << v2[i];
  cout << endl << endl;
   
  return 0;
}








24.14.replace_copy
24.14.1.std::replace_copy
24.14.2.Use replace_copy to print all elements with value 5 replaced with 55
24.14.3.Use replace_copy to replace spaces with colons
24.14.4.copy from one vector to another vector, replacing 10s with 100s with replace_copy()