PROTOC command format
Protoc-i=src-cpp_out = DRC Src\*.proto
SRC: source path;
DRC: Destination path;
When a file error cannot be opened below, the project path should be added in the Include directory file under the project Properties directory d:\!exercise\c++\protob1\protob1\
Error 1 C1083: Could not open include file: "Google/protobuf/stubs/common.h": No such file or directory d:\!exercise\c++\protob1\protob1\ Google\protobuf\generated_message_util.h 1 Protob1
When the library file cannot be opened below, the library directory under the application Engineering Properties directory adds the path to the Lib file: D:\!software\!develop\protobuf-2.5.0\protobuf-2.5.0\vsprojects\debug
Error 3 LNK1104: Unable to open file "Libprotoc.lib" D:\!exercise\c++\protob1\protob1\link protob1
Attached: source code
1#include"iostream"2#include"Person.pb.h"3#include"FStream"4 5 using namespacestd;6 #pragmaComment (lib, "Libprotoc.lib")7 #pragmaComment (lib, "Libprotobuf.lib")8 #pragmaComment (lib, "Libprotobuf-lite.lib")9 intMain ()Ten { One Lm::helloworld HW; AHW.SET_ID ( One); -HW.SET_STR ("Str"); - thecout<<"id="<Endl; -cout <<"Str"<Endl; - -Std::fstream out("PERSON.PB", Std::ios:: out| Std::ios::binary |std::ios::trunc); +Hw. Serializetoostream (& out ); - out. Close (); + A Lm::helloworld hw1; atStd::fstreaminch("PERSON.PB", Std::ios::inch|std::ios::binary); - if(!HW1. Parsefromistream (&inch ) ) { -Std::cerr <<"Failed to parse PERSON.PB."<<Std::endl; -Exit1); - } - inStd::cout <<"ID:"<< hw1.id () <<Std::endl; -Std::cout <<"Name:"<< hw1.str () <<Std::endl; to + Google::p rotobuf::shutdownprotobuflibrary (); - theSystem"Pause"); * return 0; $}
Protobuf Simple Serialization Deserialization example