• <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>
            隨筆-379  評論-37  文章-0  trackbacks-0
            下載protobuf-2.5.0(解壓到D:\下)
            編譯,在目錄D:\protobuf-2.5.0\vsprojects\Debug之下,生成若干.lib,.exe程序(好亂,中間文件和生成文件都放到一個目錄下了,眼都看花了)

            另外單獨建立新項目test
            將protobuf-2.5.0中生成的libprotobuf.lib、libprotoc.lib、protoc.exe復制到新項目Test的工作目錄下

            在新項目test工作目錄下新建文本文件test.proto
            編輯文件test.proto內容如下:

            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
            將這兩個文件加入到新項目test中,編譯新項目
            o了!




            附:新項目中使用protobuf自動生成的c++文件的相關代碼

            #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;

                // 設置數據, 并序列化到文件
                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();

                // 從文件中讀取數據, 并且反序列化
                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 小王 閱讀(9417) 評論(0)  編輯 收藏 引用 所屬分類: 開源項目
            亚洲AV无码一区东京热久久| 性做久久久久久免费观看| 国产成人无码精品久久久性色| 久久91精品国产91| 久久久精品2019免费观看| 99re久久精品国产首页2020| 久久有码中文字幕| 亚洲精品无码久久久久sm| 天天爽天天爽天天片a久久网| 内射无码专区久久亚洲| 久久精品无码午夜福利理论片| 国产精品无码久久四虎| 亚洲午夜久久久影院| 国产亚洲美女精品久久久| 日韩人妻无码精品久久免费一| 久久99精品久久久久久齐齐| 亚洲国产精品久久电影欧美| 91久久九九无码成人网站 | 久久青青国产| 97久久久精品综合88久久| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 青青青青久久精品国产h| 老男人久久青草av高清| 久久99精品免费一区二区| 久久久久久久人妻无码中文字幕爆 | 日韩人妻无码精品久久免费一 | 久久人做人爽一区二区三区| 99国内精品久久久久久久| 午夜天堂精品久久久久| 人人狠狠综合久久亚洲| 久久国产免费| 久久午夜电影网| 大伊人青草狠狠久久| 精品蜜臀久久久久99网站| 久久综合给久久狠狠97色| 亚洲精品乱码久久久久久蜜桃不卡| 久久久久久国产精品免费免费 | 91亚洲国产成人久久精品网址 | 国产成人精品综合久久久久| 国产69精品久久久久APP下载| 合区精品久久久中文字幕一区 |