stack overflow 찾아봐도 거의 2가지이다.
1. boost/preprocessor.hpp 라이브러리 사용하던가.
2. 배열 같은 컨테이너데 담아서 swith case 문 사용하던가.
둘 중에 하나였다.


How to convert an enum type variable to a string?
How to make printf to show the values of variables which are of an enum type? For instance: typedef enum {Linux, Apple, Windows} OS_type; OS_type myOS = Linux; and what I need is something like
stackoverflow.com
https://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c
Easy way to use variables of enum types as string in C?
Here's what I am trying to do: typedef enum { ONE, TWO, THREE } Numbers; I am trying to write a function that would do a switch case similar to the following: char num_str[10]; int
stackoverflow.com
물론 오래된 질문이고 답변도 오래된 답변이라 더 찾아보면 어떤 기가막힌 방법이 있을 수도 있지 않을까 한다.
우선은 찾는건 찾는거고, 우선 당장 enum (이놈의 자식) 을 문자열로 변환시켜야한다.
map을 사용하려고 한다. map key 값으로 int 들어오면 해당 enum string 값을 뱉어내게끔!
여기서 고민은 unordered_map을 사용할지 그냥 map을 사용할지다.
enum 값이 elements 들이 900여개나 된다.
어떤게 더 좋을지 찾아보다가 아래 블로그님의 글을 봤다. 엄청난 글이다. 글에 수고스러움도 보인다.
( 글 맨밑에 어느 한 분이 한 질문도 얻어갈게 많은 유익한 질문, 좋은 답변이였다. )

결론 : unorderd_map 으로 하자.
https://gracefulprograming.tistory.com/3
[C++] map vs hash_map(unordered_map)
개요 hash_map은 비표준 Container인데 반해(stdext namespace에 포함) unordered_map은 C++11에서 STL 표준 Container로 추가되었으며, (사실 TR1부터 추가되었지만 C++11에서 좀 더 최적화가 이루어졌다고 합..
gracefulprograming.tistory.com
'Work > work log' 카테고리의 다른 글
컴파일 과정, extern, static ( feat. Mutiple definition of '...' 에러 ) (0) | 2022.07.02 |
---|---|
[Work] Log 출력 매크로 참고 (0) | 2022.06.20 |
문자열 인코딩 : ASCII 코드, 유니코드, UTF-8, UTF-16 이해하기. (0) | 2022.03.30 |