I have to write a function that seeks for vowels inside list of strings.
After vowel is found it needs to be erased from list. After all vowels are erased list<string> is sorted from largest to smallest. I have tried something, but I am not very good with lists and iterators. This is what I've tried, please help me to fix this. I have put these lines in main() first to test if this would even compile.
Thanks in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
for(auto k=vowel.begin(); k!=vowel.end(); k++)
if(*k == 'A' || *k =='a' || ...) // for every letter that is a vowel
@MiiNiPaa thanks for your answer.
@L B: I know there are vectors, but I got this assigment, and I will be tested next week with something similar to this. So I am forced to do this with list<string>
Lambdas are one option, but I would like to know if there is workaround like dereferencing iterator and compare elements.
My mistake, only first element in string is removed if it is a vowel. I got a code that compiles fine but it seems to erase entire string instead of first letter only. It seems that method list.erase(i++) erases link to box with string. Here's my code. Thanks in advance. http://bpaste.net/show/189476/
You need nested loops. One to iterate over list, other to iterato over individual characters. And I highly suggest you to use remove_if with custom predicate (make it freestanding function if you have aversion for lambdas). Or else you might run into problems with consequent vowels.