Skip to content

michalfapso/enum_strings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

enum_strings

C++ enum convertible to and from string.

The source code was gathered from several sources and slightly modified. The original sources are referenced in the code.

Example

#include "enum_conversions_macro.h"
ENUM_CLASS(Day, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);

int main ()
{
	// get enum size
	std::cout << "enum size:" << EnumManager<Day>::size() << std::endl;
	
	Day e = Day::Friday;
	
	// convert enum to string
	std::string s = EnumConversions<Day>::toString(e);
	std::cout << "to string: '" << s << "'" << std::endl;
	
	// convert string to enum
	e = EnumConversions<Day>::toEnum(s);
	std::cout << "from string: " << e << " = " << (int)e << std::endl;
	
	return 0;
}

The code is usable also without macros (for those who hate them ;o), just check the main.cpp

About

c++ enum convertible to and from string

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published