Users Online
· Guests Online: 41
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
remove() Function in C++
remove() Function in C++
This C++ program demonstrates the remove() algorithm. The program creates a vector of strings and removes an element using the remove algorithm from the algorithm library.
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
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.