Guys i'm having a problem to understand these three lines of code. What i'm doing is taking three string
objects of same constructor arguments. But facing a problem to understand how code works in these three lines. I Know
begin()
function either return an iterator or const_iterator that refers to the first element of a container.
end()
function either return an iterator or const_iterator that refers to the next position after the end of the container.
erase()
function removes one or more elements from the container.
But what does remove()
function does?
This is my code:
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
string str = "<tag1 value = \"HelloWorld\">";
string str2 = "<tag1 value = \"HelloWorld\">";
string str3 = "<tag1 value = \"HelloWorld\">";
remove(str.begin(), str.end(), '\"');
str2.erase(remove(str2.begin(), str2.end(), '\"'));
str3.erase(remove(str3.begin(), str3.end(), '\"'),str3.end());
cout << str << endl;
cout << str2 << endl;
cout << str3 << endl;
}
Output:
<tag1 value = HelloWorld>">
<tag1 value = HelloWorld>>
<tag1 value = HelloWorld>