下载地址:main.cpp
修改扩展名为cpp。
前提:修改main.cpp里面的main方法
1 2
| char image[30] = "image1.jpg"; //你要添加水印图片 char waterImage[30] = "wm1.png";//你的水印图
|
在linux下执行
>g++ -o main main.cpp -lgd -ljpeg
>./main
没有评论
一篇详细讲述autoconf和automake的好文章。
原文地址:http://www.ibm.com/developerworks/cn/linux/l-makefile/

1条评论
1. 原声明:int *(*a[5])(int, char*);
变量名为a,直接用一个新别名pFun替换a就可以了:
typedef int *(*pFun)(int, char*);
原声明的最简化版:
pFun a[5];
2. 原声明:void (*b[10]) (void (*)());
变量名为b,先替换右边部分括号里的,pFunParam为别名一:
typedef void (*pFunParam)();
再替换左边的变量b,pFunx为别名二:
typedef void (*pFunx)(pFunParam);
原声明的最简化版:
pFunx b[10];
3. 原声明:doube(*)() (*e)[9];
变量名为e,先替换左边部分,pFuny为别名一:
typedef double(*pFuny)();
再替换右边的变量e,pFunParamy为别名二
typedef pFuny (*pFunParamy)[9];
原声明的最简化版:
pFunParamy e;
理解复杂声明可用的“右左法则”:从变量名看起,先往右,再往左,碰到一个圆括号就调转阅读的方向;括号内分析完就跳出括号,还是按先右后左的顺序,如此循环,直到整个声明分析完。举例:
int (*func)(int *p);
首先找到变量名func,外面有一对圆括号,而且左边是一个*号,这说明func是一个指针;然后跳出这个圆括号,先看右边,又遇到圆括号,这说明 (*func)是一个函数,所以func是一个指向这类函数的指针,即函数指针,这类函数具有int*类型的形参,返回值类型是int。
int (*func[5])(int *);
func右边是一个[]运算符,说明func是具有5个元素的数组;func的左边有一个*,说明func的元素是指针(注意这里的*不是修饰 func,而是修饰func[5]的,原因是[]运算符优先级比*高,func先跟[]结合)。跳出这个括号,看右边,又遇到圆括号,说明func数组的元素是函数类型的指针,它指向的函数具有int*类型的形参,返回值类型为int。
摘自:http://faq.csdn.net/read/217385.html
没有评论
输入s为石头,x为剪刀,p是布,机器随机生成石头剪刀布。进行比较,看谁先赢3次就OVER
代码如下:
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <iostream> #include <cstdlib> #include <time.h> using namespace std; #define WINSCORE 3 // Function PickRandomOption // * Returns a random character between 's', 'x', and 'p' char PickRandomOption (void) { char option; srand ( time (NULL) ); // (re)initialize random number generator int value = rand()%3; // Generate random number between 0 and 2 switch (value) { case 0: option='s'; break; case 1: option='x'; break; case 2: option='p'; break; } return option; } // Function WhoWins // * check which of the characters passed wins. // return values: // 0= tie, 1=the first, 2=the second, -1=error int WhoWins (char a, char b) { switch (a) { case 's': if (b=='x') return 1; else if (b=='p') return 2; else return 0; case 'x': if (b=='p') return 1; else if (b=='s') return 2; else return 0; case 'p': if (b=='s') return 1; else if (b=='x') return 2; else return 0; default: return -1; } } main () { char you, me; int mypoints=0; int yourpoints=0; int winner; do { //prompt user. cout << "\nEnter s, x or p "; //decide computer's option and say it me = PickRandomOption(); cout << "I say: " << me << "\n"; // check who is the winner winner = WhoWins (you,me); // show appropiate message: if (winner ==0) cout << "Tied\n"; else if (winner ==1) { cout << "You win\n"; yourpoints ++; } else if (winner ==2) { cout << "I win\n"; mypoints ++; } else cout << "Sorry. You entered an Invalid option\n"; // show current scoreboard. cout << "POINTS: You:" << yourpoints; cout << " Me:" << mypoints << "\n"; } while (yourpoints<WINSCORE && mypointsmypoints ) cout << "You win the competition!\n"; else cout << "I win the competition!\n"; return 0; }
|
没有评论
1到100随机生成一个数字,通过输入来比较数字大小,知道猜中为止,代码如下:
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 32 33 34 35 36 37 38 39 40 41 42
| #include <iostream> #include <cstdlib> #include <limits> #include <time.h> using namespace std; // Define the greatest possible value: #define MAX_RANGE 100 main () { int counter=0; long value,input; srand ( time (NULL) ); // Initialize random generator value = rand()%MAX_RANGE+1; // Get random between 1 and MAX_RANGE time_t start, submit; double duration; start = time(NULL); cout << "\nInsert a value between 1 and " << MAX_RANGE <> input )) { // Get user input cin.clear(); cin.ignore(numeric_limits ::max(), '\n'); cout <input ) // is value grater than the input? cout << "Value is greater than " << input; else if (value<input) // if not, is it less? cout << "Value is less than " << input; else { // else it is the correct number! cout << "That's right! Value was " << input; cout << "\nYou have needed " << counter << " attempts.\n"; } submit = time(NULL); duration = submit - start; cout << "\nthinking time:" << duration << " secords. Try again:"; } while (value!=input); return 0; }
|
没有评论
在PHP操作底层资源的时候往往会出现冲突的时候,例如调用linux命令来执行资源占用的时候。如果有人操作,那么就会导致失败。例如A正在执行命令,那么B执行命令的时候如果没有判断执行命令是否成功,则会和你系统(写入数据库)不一致。在写入数据库和执行资源这2部分如何使用事务管理呢?很少有语言层面上提供事务,一般是数据库提供事务处理。那么我们可以变相的事务处理,利用资源只能一个占用,就是同步执行。可以采用如下方法:
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 32 33 34
| function mutex_init() { $mutex_filename = FILEDIR . '/mutex.lock'; $sem_id = 220; $use_flock = false; else $use_flock = true; if ($use_flock) $mutex = fopen($mutex_filename, 'w'); else $mutex = sem_get($sem_id, 1, 0644 | IPC_CREAT , 1); } function writers_entry() { if ($use_flock) else } function writers_exit() { if ($use_flock) else }
|
那么就可以在系统初始化使用mutex_init(),然后在执行事务入口使用writers_entry(),出口使用writers_exit()
使用代码记得定义FILEDIR(锁文件路径)
没有评论
需要php4才能编译的。如果是php5将会报告错误。
没有评论
Indri Search Engine 是Lemur Toolkit下的一个子集。
Lemur除了Indri外,还有语言模型和经典的语言模型部分。
Indri是搜索引擎,Lemur是基于Indri上的一个应用工具包。
没有评论
大家一定有想法,想把WPMU的模板上的导航添加外链,这个实现其实很简单。
这里吧链接分类名为navitems作为导航的链接,只需要在theme下添加如下的代码:
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| /** * 导航实现 * * @param unknown_type $before * @param unknown_type $after */ function itheme_nav($before = '', $after = ''){ 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'category_name' => 'navitems', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '', 'search' => '' ); $results = get_bookmarks($nav_items); $output = ''; if($results){ foreach ( (array) $results as $row ) { $output .= $before; $the_link = '#'; if ( !empty($row->link_url) ) $the_link = clean_url($row->link_url); $rel = $row->link_rel; if ( '' != $rel ) $rel = ' rel="' . $rel . '"'; $desc = $row->link_description; $name = $row->link_name; $title = $desc; if ( '' != $title ) $title = ' title="' . $title . '"'; $alt = ' alt="' . $name . '"'; $target = $row->link_target; if ( '' != $target ) $target = ' target="' . $target . '"'; $output .= '<a href="' . $the_link . '">'; if ( $row->link_image != null && $show_images ) { if ( strpos($row->link_image, 'http') !== false ) $output .= "<img src="\" alt="" />link_image\" $alt $title />"; else // If it's a relative path $output .= "<img src="\" alt="" />link_image\" $alt $title />"; } else { $output .= $name; } $output .= '</a>'; $output .= "$after\n"; } } }
|
那么在具体的header.php(各种模板位置不一)上,添加自己的导航显示:
1 2 3
| //...... <?php itheme_nav( '<li>', '</li>')?> //......
|
具体的链接到WPMU后台去添加一个分类navitems,在这个分类下添加导航链接和打开的方式,这里就不具体介绍了。
2条评论
三五博客速度比其他Wordpress快的理由:
1、一般情况下,个人托管Wordpress只是简单的把WordPress代码放到PHP空间而已,没有对代码进行优化。
2、Wordpress主机不提供额外内存给用户,即不提供APC、eAccelerator、xcache等PHP加速(占用内存)。
3、Wordpress主机顶多使用SuperCache,而三五博客不仅提供SuperCache,而且还提供Memcached缓存。
4、Wordpress主机还提供其他的主机服务,例如Drupal,导致争抢CPU资源和内存资源,三五博客服务器只提供博客服务,更专业;
5、Wordpress对于多语言的处理条目太多(上万条目),并且从硬盘读起,很耗时间、而三五博客是直接把多语言包常驻内存使用。速度更快。
6、Wordpress对于博客模板信息都是从硬盘读起,对于模板数量很大的情况下,很耗时间、而这些三五博客都是常驻内存处理。
还有其他很多的优化特性,不在此一一列举……
3条评论