Skip navigation.

极湖

无不用其“极”

Google C模板

, , ,

如果您打算用C来写CGI程序,且用到模板技术,Google Ctemplate 或许正是您需要的东西。

以下是在一个日文网页上看到的例子:

代码
// 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。

crontab的时间格式用LWP::UserAgent实现“Web浏览自动化”

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31