Split strings from lines and get only different values (names) to new vector


Is there any way to split a vector (line of strings) and add only the different words to a new string (vector)?

being the result a vector of not repeated names.

Many thanks in advance.

This question is not clear enough. Can you post an example, and shows us what vector you expect back?
Do you have, for example, a vector containing these strings:
"apple", "banana", "banana", "apple", "ananas" and you want back a vector containing only "apple", "banana", "ananas"?

yes, it is better with example:
vector 1 - apple, banana, peach, ananas
vector 2 - apple, mint, peach, cherry
vector 3 - grape, cherry, guava, peach
vector 4 - lemon, orange, banana, …

a push_back to a new vector will be
= apple, grape, lemon,

I only want from first string[0] of all vectors, one of each different.
So, once first apple is pushed no more apples gets in.


1 Like

Hi, you can use a set instead of a vector, it doesn’t allow repeated items.

See this flowchart (save it!)

Edit: Not sure this solves your problem but it’s good info anyways.


I would go for a set too. If you are not creating the vectors yourself, but, for example, you are reading them from another object, I would suggest you to create an empty set, then iterate through all your vectors and for each vector insert in the set the first element.

1 Like

I’m trying to reach with set now. It seems the right option, yah. Never have used before.
Yes, I’m really trying to build dynamic menus and submenus from vectors of strings and getting it from csv. Very big cvs lists.
First menu choice’s leads to second menu items and so on.
Many thanks. Great guys!

1 Like