pike的语法非常像C++,但是它也是脚本语言,所以具有一般脚本语言的特性。一个简单的pike程序,hello world:
1 int main() 2 { 3 write("Hello world!\n"); 4 return 0; 5 }
string的用法,及命令行参数的例子:
#! /usr/local/bin/pike //下次直接打文件名就可以了 int main(int argc, array(string) argv) { write("Welcome to the Very Simple WWW Browser!\n"); string url; if(argc == 2) url = argv[1]; //命令行参数 else { write("Type the address of the web page:\n"); url = Stdio.stdin->gets(); //从标准输入中读取一行字符串 } write("URL: " + url + "\n"); return 0; }
再看看下面段小代码,会觉得更加熟悉:
1 do 2 { 3 write("Type the address of the web page:\n"); 4 url = Stdio.stdin->gets(); 5 } while(sizeof(url) == 0); //简直和C++无差
时间: 2024-10-09 00:43:21