• <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 小王 閱讀(9431) 評論(0)  編輯 收藏 引用 所屬分類: 開源項目
            亚洲人成无码久久电影网站| 亚洲∧v久久久无码精品| 久久精品www人人爽人人| 国产精品久久一区二区三区| 久久涩综合| 久久精品国产秦先生| 日本WV一本一道久久香蕉| 久久精品嫩草影院| 久久夜色精品国产亚洲av| 无码精品久久久久久人妻中字| 久久青青草原国产精品免费| 久久国产乱子伦免费精品| 国产99久久久久久免费看| 久久国产精品国产自线拍免费| 久久男人中文字幕资源站| 久久99精品国产自在现线小黄鸭| 亚洲AV无码久久| 色偷偷88欧美精品久久久| 亚洲精品美女久久久久99小说| 久久99国内精品自在现线| 深夜久久AAAAA级毛片免费看| 国产精品久久久久久搜索| 久久精品国产亚洲AV久| 亚洲熟妇无码另类久久久| 亚洲国产精品无码久久一区二区| 国产精品VIDEOSSEX久久发布| 国内精品伊人久久久久av一坑| 久久综合亚洲鲁鲁五月天| 欧美久久久久久精选9999| 18岁日韩内射颜射午夜久久成人| 久久成人永久免费播放| 久久亚洲精品成人无码网站| 久久久久久A亚洲欧洲AV冫| 久久亚洲中文字幕精品一区| 久久精品中文字幕一区| 国产精品伊人久久伊人电影| 亚洲午夜精品久久久久久人妖| 好属妞这里只有精品久久| 久久国产乱子伦精品免费强| 九九精品99久久久香蕉| 91精品国产91久久久久久青草|