标签:库
其中遇到了很多问题。
* 编译时动态链接库没有加入,导致报错
* 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