• <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)目
            国产精品久久毛片完整版| 午夜精品久久久久久中宇| 99久久国产免费福利| 久久久久99精品成人片| 伊人久久大香线蕉av不变影院| 久久精品免费一区二区三区| 亚洲国产成人精品女人久久久 | 久久久久亚洲AV成人片 | 99久久精品九九亚洲精品| 国产精品99久久久久久宅男小说| 久久99久久99精品免视看动漫| 日产久久强奸免费的看| 99麻豆久久久国产精品免费| 久久久久久久精品妇女99| 久久国产成人| 色综合久久88色综合天天| 色综合久久久久久久久五月| 一本久久免费视频| 热久久国产欧美一区二区精品| 久久青青草原精品影院| 国产精品女同久久久久电影院| 久久久噜噜噜久久中文字幕色伊伊| 久久久青草青青亚洲国产免观| 伊人久久精品无码av一区| 午夜视频久久久久一区| 国产综合精品久久亚洲| 国产精品内射久久久久欢欢 | 久久国产精品二国产精品| 国产高潮久久免费观看| AA级片免费看视频久久| 久久久久久综合一区中文字幕| 国产精品99久久免费观看| 久久久久亚洲AV无码网站| 99久久精品午夜一区二区| 97久久精品人妻人人搡人人玩| 国产高潮国产高潮久久久| 国产精品久久久久影视不卡| 久久线看观看精品香蕉国产| 久久最新精品国产| 久久久久久一区国产精品| 一本久道久久综合狠狠躁AV|