首页 > 其他 > 详细

文章标题

时间:2015-07-07 09:36:43      阅读:223      评论:0      收藏:0      [点我收藏+]

ctemplate 模板替换库的简单使用实践

其中遇到了很多问题。


*   编译时动态链接库没有加入,导致报错
*   tpl文件内容出现偏差

下面将代码呈现出来


exmaple.tpl

      {{NAME}} welcome,
      congratulations, your bounty${{VALUE}}! 
    {{#IN_CA}}your tax is:  ${{TAXED_VALUE}}. {{/IN_CA}}

test.cpp

#include <iostream>
#include <stdlib.h>
#include <string>
#include <ctemplate/template.h>
using namespace std;
int main(void)
{
    ctemplate::TemplateDictionary dict("example");
    dict.SetValue("NAME", "John Smith");
    int winnings = rand()%10000;
    dict.SetIntValue("VALUE", winnings);
    dict.SetFormattedValue("TAXED_VALUE", "%.2f", winnings*0.83);
    dict.ShowSection("IN_CA");
    ctemplate::Template *tpl =template::Template::GetTemplate("example.tpl",template::DO_NOT_STRIP);
    string output;
    tpl->Expand(&output, &dict);
    cout<<output;
    return 0;
}

编译命令
g++ -g -o test test.cpp /usr/local/lib/libctemplate_nothreads.a


欢迎提出建议或意见,谢谢

版权声明:本文为博主原创文章,未经博主允许不得转载。

文章标题

原文:http://blog.csdn.net/yunlliang/article/details/46779131

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!