mardi 1 mai 2018

How to create an std::vector out of an std::string which contains values separated by a common delimiter [duplicate]

This question already has an answer here:

Scenario:
Unfortunately due to some legacy code, I have a std::string which contain some int values and separated by spaces like this:

std::string legacy_code_string = "3 8 7 10 5 16";

Note that the common delimiter used in a space " " and all values are ints.

I want to create an std::vector<int> out of this

std::vector<int> GetVectorFromEncodedValuesInString(const std::string & str) {

}

Question:
How I can do this the best way possible?

Aucun commentaire:

Enregistrer un commentaire