Protobuf Simple Serialization Deserialization example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.