ImGUI Combo + std::vector<std::string>

How can I fill a ImGui::Combo with a std::vector<std::string> variable?

Like:

// My string array:
std::vector<std::string> my_vec;

// Add elements:
my_vec.push_back("car");
my_vec.push_back("sun");
my_vec.push_back("good");

// Create a Combo Box:
static int item_current = 0;
ImGui::Combo("Example", &item_current, my_vec);

Or may be there is another good way to do that?

Use BeginCombo/EndCombo and submit the elements yourself.
Don’t use Combo, don’t make copy of your data.

1 Like