package MyPackage;
message MyMessage
{
enum RequestType {
Login = 0;
Logout = 1;
}
optional RequestType requestType = 1;
}
#include<iostream>
#include "my.pb.h"
using namespace std;
using namespace MyPackage;
int main(int argc, char** argv)
{
MyMessage::RequestType type = MyMessage::Login;
// Print the name of enum item
cout << MyMessage::RequestType_Name(type) << endl;
}
$g++ main.cpp my.pb.cc -lprotobuf
$./a.out
Login