• <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)目
            伊人情人综合成人久久网小说| 久久亚洲欧美国产精品| 久久精品二区| 久久久久一级精品亚洲国产成人综合AV区| 久久www免费人成看国产片| 午夜精品久久久久久影视riav| 亚洲国产精品久久电影欧美| 日本精品久久久久中文字幕8| 无夜精品久久久久久| 99re久久精品国产首页2020| 亚洲国产天堂久久久久久| 精品久久久久久久久中文字幕| 色天使久久综合网天天| 国产A级毛片久久久精品毛片| 亚洲av伊人久久综合密臀性色| 久久黄视频| 91久久福利国产成人精品| 日产精品久久久一区二区| 久久99国产精品久久99小说 | 久久久这里有精品| 亚洲狠狠综合久久| 69久久夜色精品国产69| 无遮挡粉嫩小泬久久久久久久| 色诱久久av| 久久频这里精品99香蕉久| 久久久91人妻无码精品蜜桃HD| www.久久精品| 久久精品嫩草影院| 亚洲国产精品久久久久婷婷软件 | 久久国产精品波多野结衣AV| 伊人久久大香线焦综合四虎| 久久国产精品99精品国产987| 成人久久综合网| 欧美亚洲国产精品久久蜜芽 | 99久久中文字幕| 精品无码久久久久久尤物| 久久精品一本到99热免费| 国产成年无码久久久久毛片| 高清免费久久午夜精品| 青青草国产成人久久91网| 久久精品成人一区二区三区|