I have an unordered map like this:
std::unordered_map<std::string, std::string> wordsMap;
I also have string like this
std::string text = "This is really long text. Sup?";
I'm looking for the fastest solution to split the text string by space
and add each word to the unordered map without using third-party libraries. I'll only split it by space, so I'm not looking for solution with changeable delimiter.
I figured out this solution:
void generateMap(std::string const& input_str, std::string const& language) {
std::string buf; // Have a buffer string
std::stringstream ss(input_str); // Insert the string into a stream
while (ss >> buf)
wordsMap.insert({ buf, language });
}
Are there any faster solutions?