.proto文件示例

message Configure
{
required string host = ;
required uint32 port = ;
}

写配置文件

Configure config;

config.set_host("127.0.0.1");
config.set_port(8080); string contect; google::protobuf::TextFormat::PrintToString(config, & contect);
ofstream fout;

fout.open("config.cfg", ios::out| ios_base::ate);

if (!fout.is_open())
{
fprintf(stderr, "open config.cfg fail\n");
return -;
} fout << contect <<endl; fout.flush(); fout.close();

读配置文件

int fd = open("config.cfg", O_RDONLY);

if (fd < )
{
printf("open config.cfg failure:%s \n",strerror(errno));
return false;
} google::protobuf::io::FileInputStream fileInput(fd); fileInput.SetCloseOnDelete(true); google::protobuf::TextFormat::Parse(&fileInput, &config);

使用protobuf编写配置文件以及读写的更多相关文章

  1. 配置文件Java读写

    今天把配置文件的Bug修复了,总结一下Java配置文件如何读写 配置文件的格式 以.properties后缀结尾,内容不出现空格和双引号 //config.properties Driver=com. ...

  2. C语言编写的bmp读写程序

    C语言编写的bmp读写程序 建议先把bmp的数据存储格式了解下 <span style="font-size:16px;">#include "Windows ...

  3. C语言ini格式配置文件的读写

    依赖的类 /*1 utils.h *# A variety of utility functions. *# *# Some of the functions are duplicates of we ...

  4. 用yaml来编写配置文件

    yaml是一个数据序列化的标准,适用于所有开发语言,最大的特点是可读性好. yaml的一个主要应用方向就是编写配置文件,有非常多的系统和框架采用yaml进行配置. yaml有以下基本规则: 1.大小写 ...

  5. java文件操作(普通文件以及配置文件的读写操作)

    转自:java文件操作(普通文件以及配置文件的读写操作) 读取普通文件 : /** * xiangqiao123欢迎你 如果对代码有疑问可以加qq群咨询:151648295 * * 读取MyFile文 ...

  6. C#+Access 员工信息管理--简单的增删改查操作和.ini配置文件的读写操作。

    1.本程序的使用的语言是C#,数据库是Access2003.主要是对员工信息进行简单的增删改查操作和对.ini配置文件的读写操作. 2.代码运行效果如下: 功能比较简单.其中在得到查询结果后,在查询结 ...

  7. java配置文件的读写

    最近在做一个爬虫项目时,用到了读写配置文件的方法,记录下来以后可能用的到. Properties pro = new Properties(); boolean IsFirst = true; //从 ...

  8. tensorflow serving 编写配置文件platform_config_file的方法

    1.安装grpc gRPC 的安装: $ pip install grpcio 安装 ProtoBuf 相关的 python 依赖库: $ pip install protobuf 安装 python ...

  9. 4.caffe:train_val.prototxt、 solver.prototxt 、 deploy.prototxt( 创建模型与编写配置文件)

    一,train_val.prototxt name: "CIFAR10_quick" layer { name: "cifar" type: "Dat ...

随机推荐

  1. POJ 1664 把苹果

     把苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25785   Accepted: 16403 Descript ...

  2. LeetCode: Best Time to Buy and Sell Stock II [122]

    [题目] Say you have an array for which the ith element is the price of a given stock on day i. Design ...

  3. java编程接口(5) ------ button和button组

    这篇文章是由自己的学习笔记,欢迎转载,但请注明出处:http://blog.csdn.net/jesson20121020 了解了布局管理器和Swing事件模型,那么剩下的就是Swing 的各个组件了 ...

  4. AFNetworking3.0 POST请求

    // 请求管理者 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializer ...

  5. Jquery页面中添加键盘按键事件,如ESC事件

    $(document).keydown(function(event){ if(event.keyCode == 38 || event.keyCode == 104){ i--; if(i<= ...

  6. sessionStorage、localStorage、cookie

    sessionStorage 和 localStorage 是HTML5 Web Storage API 提供的,可以方便的在web请求之间保存数据.有了本地数据,就可以避免数据在浏览器和服务器间不必 ...

  7. SQL Server中存储过程比直接运行SQL语句慢的原因

    原文:SQL Server中存储过程比直接运行SQL语句慢的原因 在很多的资料中都描述说SQLSERVER的存储过程较普通的SQL语句有以下优点: 1.       存储过程只在创造时进行编译即可,以 ...

  8. 日积月累系列之省市选择器(js源码)

    省市选择器是大家经常用到的, 但网上找的省市选择器都不是很实用,于是自己写了移动端的省市选择器. 界面: 源码结构: 演示地址:http://component.cform.cn/city/ 演示二维 ...

  9. OCP-1Z0-051-题目解析-第10题

    10. View the Exhibit and examine the structure of the PROMOTIONS table. Each promotion has a duratio ...

  10. 【c#操作office】--OleDbDataAdapter 与OleDbDataReader方式读取excel,并转换为datatable

    OleDbDataAdapter方式: /// <summary> /// 读取excel的表格放到DataTable中 ---OleDbDataAdapter /// </summ ...