Here is the source code of the C++ program which demonstrates the remove() algorithm. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ program to demonstrate remove algorithm
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
typedef std::vector <std::string>::iterator iterator;
void print(iterator b, iterator e)
{
iterator i;
for (i = b; i != e; i++)
{
std::cout << *i << " ";
}
std::cout << std::endl;
}
int main()
{
std::vector <std::string> v;
iterator i;
v.push_back("China");
v.push_back("Dubai");
v.push_back("Boston");
v.push_back("France");
v.push_back("Hungary");
v.push_back("Australia");
std::cout << "Places to visit : ";
print(v.begin(), v.end());
i = remove(v.begin(), v.end(), "Boston");
std::cout << "Visited Boston" << std::endl;
std::cout << "Places to visit : ";
print(v.begin(), i);
}
$ a.out Places to visit : China Dubai Boston France Hungary Australia Visited Boston Places to visit : China Dubai France Hungary Australia