Code:
#include <vector>
#include <string>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
vector<string> strVect;
strVect.push_back("One");
strVect.push_back("");
strVect.push_back("Two");
strVect.push_back("Three");
strVect.push_back("");
strVect.push_back("Four");
// Print original vector contents
copy( strVect.begin(), strVect.end(), ostream_iterator<string>(cout,"\n") );
// Erase empty string elements from the vector
vector<string>::iterator start;
start = remove_if( strVect.begin(), strVect.end(), bind1st( equal_to<string>(), string("") ) );
strVect.erase( start, strVect.end() );
// Print modified vector contents
cout << "****\n";
copy( strVect.begin(), strVect.end(), ostream_iterator<string>(cout,"\n") );
return 0;
}
Output:
Code:
One
Two
Three
Four
****
One
Two
Three
Four