CPP   26
assert string vector
Guest on 7th February 2023 02:07:16 AM


  1. #include <iostream>
  2. #include <cassert>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.   cout << "Illustrating the generic replace algorithm."
  11.        << endl;
  12.   string s("FERRARI");
  13.   vector<char> vector1(s.begin(), s.end());
  14.  
  15.   // Replace all occurrences of R by S:
  16.   replace(vector1.begin(), vector1.end(), 'R', 'S');
  17.  
  18.   assert (string(vector1.begin(), vector1.end()) ==
  19.          string("FESSASI"));
  20.   cout << " --- Ok." << endl;
  21.   return 0;
  22. }

Raw Paste

Login or Register to edit or fork this paste. It's free.