Q:

Define a map that associates words with a list of line numbers on which the word might occur

0

Define a map that associates words with a list of line numbers on which the word might occur.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <map>
#include <list>
#include <string>
#include <iostream>

int main() {
  std::map<std::string, std::list<int>> words{
      {"ghi", {100, 200}}, {"abc", {1, 3, 5}}, {"def", {2, 4}}};

  for (const auto &w : words) {
    std::cout << w.first << ":";
    for (const auto &l : w.second)
      std::cout << " " << l;
    std::cout << std::endl;
  }

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now