This is probably a simple question, but I can't get it to work. I've searched and have tried all the suggestions people gave for the OR operator ||, but my code just won't properly use it.
So here's what I've got: This part of my code looks at a vector (currently around ~20,000 entries long, but later will be in the millions) and erases all elements that contain the keywords: " event", " /event", " rwgt", and " /rwgt". It works perfectly fine when I use four for loops, one for each keyword like so:
for (int j = 0; j< myvec.size()-1;j++) {
if(myvec[j] == " <event>") { //erase all instances of "<event>"
myvec.erase(myvec.begin()+j);
}
}
for (int j = 0; j< myvec.size()-1; j++) {
if(myvec[j] == " </event>") { //erase all instances of "</event>"
myvec.erase(myvec.begin()+j);
}
}
for (int j = 0; j< myvec.size()-1; j++) {
if(myvec[j] == " <rwgt>") { //erase all instances of "<rwgt>"
myvec.erase(myvec.begin()+j);
}
}
for (int j = 0; j< myvec.size()-1; j++) {
if(myvec[j] == " </rwgt>") { //erase all instances of "</rwgt>"
myvec.erase(myvec.begin()+j);
}
}
However this is getting fairly computationally expensive (it takes a few minutes right now with only 20,000 entries; I can't imagine it when we get to the millions!) So I wanted to combine all four keywords into one for loop using the || (OR) operator like so:
for (int j = 0; j< myvec.size()-1;j++) {
if(myvec[j] == " <event>" || myvec[j] == " </event>" || myvec[j] == " <rwgt>" || myvec[j] == " </rwgt>") { //erase all instances of "<event>"
myvec.erase(myvec.begin()+j);
}
}
However this is taking even longer than the original four for loops, and it ends up giving me a segmentation fault (core dumped) error, which to my knowledge means the vector is now empty somehow.
Does anyone have any ideas on how to fix this?
Thanks in advance!