假設以下是定義的test.proto文件
package T; message Test { optional int32 id = 1; }
獲取屬性及值,並打印
#include "cpp/test.pb.h" #include <iostream> #include <string> int main() { T::Test config; std::string message; /* 加載×××.pb.h文件代碼 */ message = config.Utf8DebugString(); std::cout << message << std::endl; return 0; }
參考:https://www.p-chao.com/2017-09-04/protobuf%E5%8F%8D%E5%B0%84%E8%AF%A6%E8%A7%A3/