C++ Vector.erase() causing segmentation fault
c++, segmentation-fault, vector
Solution
It appears that you want the usual remove-erase idiom:
#include <algorithm>
#include <functional>
myvector.erase(std::remove_if(myvector.begin(), myvector.end(),
std::mem_fn(&std::string::empty)),
myvector.end());
Problem
I have a C++ vector and it has some blank elements in it. I wanted to remove any empty string elements from the vector. I tried this code: ``` for (i = 0; i < myvector.size();i++) { if (myvector[i] == "") { myvector.erase(myvector.begin()+i); } } ``` When I run this code I get a segmentation fault. Is there something wrong with it? Or does this code work for any of you?