junxnone / xwiki

https://junxnone.github.io/xwiki/
0 stars 0 forks source link

Programing CPP switch #81

Open junxnone opened 2 years ago

junxnone commented 2 years ago

Reference

Brief

std::map

#include <map>
#include <string>

enum StringValue { evNotDefined, 
                          evStringValue1, 
                          evStringValue2, 
                          evStringValue3, 
                          evEnd };

std::map<std::string, StringValue> s_mapStringValues;

s_mapStringValues["x"] = evStringValue1;
s_mapStringValues["y"] = evStringValue2;
s_mapStringValues["z"] = evStringValue3;

switch(s_mapStringValues[InputString])
    {
      case evStringValue1:
        cout << "Detected the first valid string." << endl;
        break;
      case evStringValue2:
        cout << "Detected the second valid string." << endl;
        break;
...
...