0

In python, you can easily define a dict object in the head of a python file or in another file and import it. Using that dict as a mapping where key corresponds to a value you want. For instance:

MIMES = {
'html': 'text/html',
'js': 'application/javascript',
...
}

What's the recommended way to set something similar up in C++. There are a few instances where I need to do this in different contexts so I'm not looking for a Mime-type library. Just want to find out what best practice is for this type of situation in C++.

Jeff U.
  • 616
  • 1
  • 6
  • 12

1 Answers1

1

From comments, got this working using a std::map in the head of the class file using it.

#include <map>
std::map<std::string, std::string> mimes = {
    {"html", "text/html"},
    {"png", "image/png"},
    ...
};

And then accessing the values using:

mimes["html"];
Jeff U.
  • 616
  • 1
  • 6
  • 12
  • Thank you, i'm definitely in the deep end of learning at the moment, nose buried in Stroustrop books. These will be a great help! – Jeff U. Mar 23 '17 at 15:04