• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-380  評論-37  文章-0  trackbacks-0
            下載protobuf-2.5.0(解壓到D:\下)
            編譯,在目錄D:\protobuf-2.5.0\vsprojects\Debug之下,生成若干.lib,.exe程序(好亂,中間文件和生成文件都放到一個(gè)目錄下了,眼都看花了)

            另外單獨(dú)建立新項(xiàng)目test
            將protobuf-2.5.0中生成的libprotobuf.lib、libprotoc.lib、protoc.exe復(fù)制到新項(xiàng)目Test的工作目錄下

            在新項(xiàng)目test工作目錄下新建文本文件test.proto
            編輯文件test.proto內(nèi)容如下:

            package Test;
            message Person
            {
               required
            string name = 1;
               required int32 id
            = 2;
               optional
            string email = 3;
            }

            在控制臺中輸入命令
            protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/test.proto
            (翻譯一下:protoc -I=D:\test\test --cpp_out=D:\test\test D:\test\test\person.proto)
            生成文件:
            person.pb.cc
            person.pb.h
            將這兩個(gè)文件加入到新項(xiàng)目test中,編譯新項(xiàng)目
            o了!




            附:新項(xiàng)目中使用protobuf自動生成的c++文件的相關(guān)代碼

            #include "stdafx.h"
            #include "person.pb.h"
            #include <iostream>
            #include <fstream>


            int _tmain(int argc, _TCHAR* argv[])
            {
                // Verify that the version of the library that we linked against is
                // compatible with the version of the headers we compiled against.
                GOOGLE_PROTOBUF_VERIFY_VERSION;

                // 設(shè)置數(shù)據(jù), 并序列化到文件
                Test::Person person;
                person.set_id( 123 );
                person.set_name( "abc" );
                person.set_email( "abc@163.com" );

                std::fstream out( "person.pb", std::ios::out | std::ios::binary | std::ios::trunc );
                person.SerializeToOstream( &out );
                out.close();

                // 從文件中讀取數(shù)據(jù), 并且反序列化
                Test::Person person1;
                std::fstream in( "person.pb", std::ios::in | std::ios::binary );
                if ( !person1.ParseFromIstream( &in ) ) {
                  std::cerr << "Failed to parse person.pb." << std::endl;
                  exit(1);
                }

                std::cout << "ID: " << person1.id() << std::endl;
                std::cout << "name: " << person1.name() << std::endl;
                if ( person1.has_email() ) {
                  std::cout << "e-mail: " << person1.email() << std::endl;
                }

                // Optional:  Delete all global objects allocated by libprotobuf.
                google::protobuf::ShutdownProtobufLibrary();

                getchar();

             return 0;
            }







            posted on 2013-11-22 11:07 小王 閱讀(9438) 評論(0)  編輯 收藏 引用 所屬分類: 開源項(xiàng)目
            漂亮人妻被黑人久久精品| 亚洲综合婷婷久久| 国产99久久久国产精品小说| 精品多毛少妇人妻AV免费久久| 色99久久久久高潮综合影院| 亚洲va久久久噜噜噜久久天堂| 青草影院天堂男人久久| 色诱久久av| 青青草国产成人久久91网| 国产毛片欧美毛片久久久| 婷婷综合久久狠狠色99h| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 亚洲七七久久精品中文国产| 日韩人妻无码精品久久免费一 | 久久精品18| 久久99国产乱子伦精品免费| 一97日本道伊人久久综合影院| 97久久精品午夜一区二区| 久久综合亚洲色一区二区三区| 国产毛片久久久久久国产毛片 | 麻豆亚洲AV永久无码精品久久| 久久99久久成人免费播放| 久久精品无码午夜福利理论片| 怡红院日本一道日本久久| 久久婷婷五月综合97色一本一本 | 人妻系列无码专区久久五月天| 97久久精品人妻人人搡人人玩| A级毛片无码久久精品免费 | 蜜臀久久99精品久久久久久小说 | 午夜不卡久久精品无码免费| 三级韩国一区久久二区综合 | 91久久精一区二区三区大全| 色妞色综合久久夜夜| 一级a性色生活片久久无少妇一级婬片免费放 | 无码八A片人妻少妇久久| 久久久艹| 蜜桃麻豆www久久国产精品| 欧美大战日韩91综合一区婷婷久久青草| 久久国产乱子伦精品免费强| 久久se精品一区精品二区| 91精品国产91久久久久久|