Google C模板
Thursday, 19. April 2007, 07:36:01
以下是在一个日文网页上看到的例子:
代码
// test.cc
#include<string>
#include<iostream>
#include<google/template.h>
int main(void){
google::TemplateDictionary dict("example");
dict.SetValue("TITLE", "Hello Google C Template");
dict.SetValue("HEADER", "&");
std::string out;
google::Template *tpl = google::Template::GetTemplate("test.tpl", google::DO_NOT_STRIP);
tpl->Expand(&out, &dict);
std::cout<< out<< std::endl;
return 0;
}
<!-- test.tpl -->
<html>
<head><title>{{TITLE}}</title></head>
<body
<h1>{{HEADER:h}}</h1>
</body>
</html>
编译
# g++ test.cc -lpthread -lctemplate
执行
# ./a.out
<!-- test.tpl --> <html> <head><title>Hello Google C Template</title></head> <body <h1>&</h1> </body> </html>
以上程序在Cygwin和Linux下均编译通过。
Cygwin下编译生成的Exe文件竟然有1.6M,Linux下编译出来的可执行文件不到10k。







