I have the following function that loops through a vector and get the output of a public member functions. This output is a constant like 1, 8 or 3 etc.
void testItems(const TestObjectList* const testObject) {
std::vector<ObjectTestFirst> testobjects = testObject->getTestObjects();
std::vector<ObjectTestFirst>::iterator itr;
std::stringstream strbuffer;
for (itr = testobjects.begin(); itr != testobjects.end(); itr++){
strbuffer << tc.toString(itr->getTimest()) << ",\t"
<< itr->getObjectTest1() << ",\t"
<< itr->getObjectTest2() << ",\t"
<< itr->getObjectTest3() << ",\t"
<< std::endl;
}
outfile << strbuffer.str() << std::endl;
}
I have a definition of these constants in a header file that I import (hpp) represented as a enum
:
enum TestObjectClass {
TestObjectClass_Zero = 0,
TestObjectClass_TestApple = 1,
TestObjectClass_TestOrange = 8,
TestObjectClass_TestBanana = 3,
};
In the first code snippet that I show, the testItems
function, how do I check the output of the public member function with the enum
and print the enum
name?
Example: itr->getObjectTest1() << ",\t"
outputs 8 - I then check the enum and it match TestObjectClass_TestOrange = 8 so I print out TestObjectClass_TestOrange instead of the constant (8).