简介:google ctemplate:简单易用的文字模板
来源:互联网 发布:外贸企业数据 编辑:程序博客网 时间:2024/06/05 07:38
CTemplate 是一个简单实用、功能强大的文字模板(template language),适用于使用C++语言开发的应用程序。 其解决的主要问题是将文字表达和逻辑分离开来:文字模板解决如何用合适的文字和形式来表达的问题,而逻辑问题则由文字模板的调用者在源代码中完成。
下面有一个简单的例子让我们初步了解其概念,介绍了如何在你的程序中应用CTemplate:
首先创建一个模板文件,命名为example.tpl,以文本方式输入以下内容:
{{NAME}}你好,
恭喜你中奖了,奖金总额是:${{VALUE}}!
{{#IN_CA}}您应缴纳的税金总额为:${{TAXED_VALUE}}。{{/IN_CA}}
在C++程序中我们可以这样调用:
#include <stdlib.h>
#include <string>
#include <iostream>
#include <google/template.h>
int main(int argc, char** argv)
{
google::TemplateDictionary dict("example");
dict.SetValue("NAME", "John Smith");
int winnings = rand() % 100000;
dict.SetIntValue("VALUE", winnings);
dict.SetFormattedValue("TAXED_VALUE", "%.2f", winnings * 0.83);
// For now, assume everyone lives in CA.
// (Try running the program with a 0 here instead!)
if (1)
{
dict.ShowSection("IN_CA");
}
google::Template* tpl = google::Template::GetTemplate("example.tpl",
google::DO_NOT_STRIP);
std::string output;
tpl->Expand(&output, &dict);
std::cout << output;
return 0;
}
- 简介:google ctemplate:简单易用的文字模板
- 简介:google ctemplate:简单易用的文字模板
- 简介:google ctemplate:简单易用的文字模板
- Google开源html模板库ctemplate的完整使用示例
- Ctemplate的简介
- Google CTemplate:
- ctemplate模板
- C++模板引擎Ctemplate的介绍
- C++模板引擎Ctemplate的介绍
- C++模板引擎Ctemplate的介绍
- C++ 模板引擎 Ctemplate 的介绍
- Google开源C++模板库ctemplate完整使用示例
- ctemplate简单使用test
- [置顶] 使用 acl_cpp 的 HttpServlet 类及 google 的 ctemplate 库编写 WEB 应用
- opencv输出文字 opencv简单的图像模板匹配代码
- ctemplate在Windows下的编译
- Google benchmark:一个简单易用的C++ benchmark库
- ctemplate使用
- 如何更改linux下的Apache端口号
- .NET C# 唯一进程判断
- 在redhat linux上加双网卡,网关,路由
- 一个有趣的心理测试,大家一起来试试(zt).
- Python多线程
- 简介:google ctemplate:简单易用的文字模板
- MySQL主从服务器的一些技巧
- 【转】DBA需要的技能
- 【转】我说一下我学习oracle的经历
- 输入两个整数 n 和 m,从数列1,2,3.......n 中 随意取几个数, 使其和等于 m ,要求将其中所有的可能组合列出来.
- mysql(2) access denied for user 的解决方法
- java多线程基本知识
- LED驱动实例
- [linux]vi/vim中的替换命令详解