• <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  評(píng)論-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;
            }

            在控制臺(tái)中輸入命令
            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自動(dòng)生成的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 小王 閱讀(9447) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 開源項(xiàng)目
            91久久精品91久久性色| 欧美亚洲国产精品久久久久| 久久久久久国产精品免费无码| 亚洲国产精品无码久久久不卡| 国内精品久久久久久久97牛牛 | 国产99久久久国产精品小说| 久久91精品国产91久| 97久久精品国产精品青草| 久久久久这里只有精品 | 日本道色综合久久影院| 久久精品国产精品亚洲人人| 久久久一本精品99久久精品88| 亚洲一本综合久久| 欧美精品久久久久久久自慰| 久久高清一级毛片| 国产精品久久国产精品99盘| 免费精品久久天干天干| 日韩精品久久久久久| 午夜不卡久久精品无码免费| 久久免费视频一区| 国产精品内射久久久久欢欢| 久久精品无码午夜福利理论片| 亚洲一级Av无码毛片久久精品| 久久99亚洲综合精品首页| 亚洲午夜久久影院| 国产精品美女久久久| 亚洲精品无码久久久久去q| 亚洲欧美精品一区久久中文字幕| 国内精品久久久久久中文字幕| 久久免费精品一区二区| 精品国产一区二区三区久久久狼| 精品熟女少妇AV免费久久| 少妇熟女久久综合网色欲| 日日狠狠久久偷偷色综合96蜜桃| 久久中文字幕无码专区| 久久婷婷人人澡人人| 欧美激情精品久久久久久| 国内精品久久国产| 99久久国产宗和精品1上映| 久久精品国产亚洲AV无码娇色| 蜜臀av性久久久久蜜臀aⅴ|