2

I have a C++ Testing.hh header file in which I have declared this ENUM -

enum TestTypeOpt {TestingOne, TestingTwo};

Now in my Testing.cc class I am trying to print out TestingOne and TestingTwo string from the enum as shown below

 cout << "From command" << Testing::TestingOne << endl;
 cout << "From command" << Testing::TestingTwo << endl;

But above cout prints out 0 and 1 somehow? I recently started working with C++ so little bit confuse.

Is there anything wrong I am doing? I am just trying to print actual string value from the enum class.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
john
  • 11,311
  • 40
  • 131
  • 251

1 Answers1

0

Someone please correct me if there is a better approach, but the way I know to do this is with macros.

Just type #define str(x) #x This replaces x with the name as it was written in the code.

Then use for example: cout << "From command" << str(Testing::TestingOne) << endl;

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
andreee
  • 4,459
  • 22
  • 42