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

            另外單獨(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
            將這兩個文件加入到新項(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 小王 閱讀(9447) 評論(0)  編輯 收藏 引用 所屬分類: 開源項(xiàng)目
            看全色黄大色大片免费久久久| 精品国产乱码久久久久久呢| 国产福利电影一区二区三区,免费久久久久久久精 | 久久影视综合亚洲| 国产精品久久久香蕉| 久久国产精品一国产精品金尊| 久久人做人爽一区二区三区| 最新久久免费视频| 热99RE久久精品这里都是精品免费 | 国内精品久久久久影院优| 久久精品不卡| 成人资源影音先锋久久资源网| 久久人人爽人人爽人人爽 | 久久免费国产精品一区二区| 久久大香萑太香蕉av| 国产午夜精品理论片久久| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 久久婷婷五月综合色奶水99啪| 欧美激情精品久久久久久久九九九| 99久久99久久久精品齐齐| 久久精品国产99国产精品导航| 久久精品亚洲精品国产欧美| 久久这里只有精品首页| MM131亚洲国产美女久久| 久久ZYZ资源站无码中文动漫| 狠狠色丁香久久婷婷综合_中| 欧美激情精品久久久久久| 久久国产成人亚洲精品影院| 日本福利片国产午夜久久| 久久九九青青国产精品| 久久精品国产秦先生| 久久精品国产半推半就| 久久国产乱子伦精品免费强 | 久久国产精品二国产精品| 精品国产乱码久久久久久浪潮| 国内精品久久久久久久亚洲| 国产高潮国产高潮久久久91 | 久久99国产综合精品免费| 国产精品视频久久| 91性高湖久久久久| 久久成人18免费网站|