• <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程序(好亂,中間文件和生成文件都放到一個目錄下了,眼都看花了)

            另外單獨建立新項目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 小王 閱讀(9433) 評論(0)  編輯 收藏 引用 所屬分類: 開源項目
            国产免费久久精品丫丫| 久久99国产精品一区二区| 久久久久久久尹人综合网亚洲 | 九九精品99久久久香蕉| 精品无码久久久久国产| 久久九九全国免费| 亚洲国产成人久久综合一区77| 久久免费视频1| 国产精品无码久久久久久| 中文字幕一区二区三区久久网站| 欧美日韩精品久久久久| 国内精品久久久久影院日本 | 久久国产热精品波多野结衣AV| 国产精品久久久久久久| 久久久久亚洲精品男人的天堂| 色诱久久久久综合网ywww | 精品久久综合1区2区3区激情| 国产激情久久久久久熟女老人| 97久久精品人人澡人人爽| 亚洲色欲久久久综合网| 久久综合亚洲色HEZYO国产| 狠色狠色狠狠色综合久久| 亚洲精品无码久久久影院相关影片| 久久96国产精品久久久| 亚洲欧美成人久久综合中文网| 久久久精品一区二区三区| 蜜臀av性久久久久蜜臀aⅴ | 久久只有这精品99| 久久精品国产色蜜蜜麻豆| 人妻久久久一区二区三区| 久久91精品国产91| 亚洲午夜精品久久久久久浪潮| 99久久精品免费看国产| 国产精品久久久久无码av| 精品久久久久香蕉网| 国产成人精品白浆久久69| 少妇久久久久久久久久| 欧美牲交A欧牲交aⅴ久久| 亚洲AV无码久久精品狠狠爱浪潮| 久久亚洲AV成人无码软件| 尹人香蕉久久99天天拍|