1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <string>
#include <iostream>
#include <cassert>
enum AA {A, R, N, D, C, Q, E, G, H, I, L, K, M, F, P, S, T, W, Y, V, B, Z, X, GO, GE, GT, AA_COUNT};
static const char * enumStrings[AA_COUNT]={"A", "R", "N", "D", "C",
"Q", "E", "G", "H", "I", "L",
"K", "M","F", "P", "S", "T",
"W", "Y", "V", "B", "Z", "X",
"GO", "GE", "GT"};
std::string const enumToString(AA value)
{
return std::string(enumStrings[value]);
}
AA stringToEnum(std::string const & value)
{
for(int i =0;i< AA_COUNT;++i)
{
if(value == enumStrings[i])
{
return AA(i);
}
}
assert(!"You should never come here");
}
int main()
{
std::cout<<enumToString(A)<<std::endl;
std::cout<<stringToEnum("A");
return 0;
} |
Partager