I have a std::vector of std::strings containing data similar to this:
[0] = "" [1] = "Abc" [2] = "Def" [3] = "" [4] = "Ghi" [5] = "" [6] = ""
How can I get a vector containing 4 lines from 1 to 4? (i.e. I want to trim all empty lines from the beginning and end of the vector):
[0] = "Abc" [1] = "Def" [2] = "" [3] = "Ghi"
I am currently using a formatted iterator to go to "Abc" and the reverse iterator to go back to "Ghi" and then create a new vector using these iterators. This method works, but I want to know if there is an easier way to crop these elements.
PS I am C ++ noob.
Edit
In addition, I must mention that a vector can consist entirely of empty strings, in which case a vector of size 0 is the desired result.
source share