摘要: 1 #include <sys/time.h> /* 原型: int gettimeofday( struct timeval *tv, struct timezone *tz ); 功能: 获取当前精确时间。在一段代码前后分别使用gettimeofday可以计算代码执行时间. 参数: 其参数tv是保存获取时间结果的结构体,参数tz用于保存时区结果(若不使用则传入NULL即可)。 返回值:成功则返回0,失败返回-1,错误代码存于errno struct timeval {long tv_sec; // 秒数long tv_usec; // 微秒数}struct timezone{ 阅读全文
posted @ 2012-09-12 22:08 helloweworld 阅读(593) 评论(0) 推荐(0) 编辑
摘要: 1 #include <arpa/inet.h> /* 表达式格式(presentation):形如192.168.0.1,ipv6 X:X:X:X:X:X:X:X 数值格式(numeric):存储地址的二进制形式。 */ /* 原型:int inet_pton( int family, const char *strptr, void *addrptr ); 功能:将字符串strptr(即表达格式的地址)转换为网络地址。 参数:family既可以是AF_INET,也可以是AF_INET6; strptr指向ASCII地址的首地址(***.***.***.***格式),addrpt 阅读全文
posted @ 2012-09-12 21:30 helloweworld 阅读(1050) 评论(0) 推荐(0) 编辑
摘要: 一、IPV4套接字地址结构#include<netinet/in.h> /**IPV4套接字地址结构**/ structin_addr { in_addrs_addr;//32位IPV4地址,这是无符号整数,网络字节序 }; /*POSIX只关注sin_family,sin_port,sin_addr,所有网络套接字地质结构都至少16字节*/ structsockaddr_in { uint8_tsin_len;//无符号八位整形,套接字地址长度(16字节) sa_family_tsin_family;//unsignedshort in_port_tsin_port;//16位T 阅读全文
posted @ 2012-09-12 20:25 helloweworld 阅读(671) 评论(0) 推荐(0) 编辑
摘要: 先CTRL+B(Project->Build all)再CTRL+F11; 阅读全文
posted @ 2012-09-11 23:23 helloweworld 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 法一:直接新立得。法二:我的电脑D:\eclipse linux cc++ 版本 安装包拷贝到ubuntu中。1、终端到拷贝的目录下 ./jdk-6u13-linux-i586.bin2、./eclipse3、如果提示jre啥的找不到,吧1中的相应文件拷贝到提示的位置即可。 阅读全文
posted @ 2012-09-11 23:15 helloweworld 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 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 #include<stdio.h> #include<string.h> #include<stdarg.h> intdemo( char* msg, ... ) { va_list argp; //1、va_list变量是指向参数的指针; char* para; va_start( argp, msg ); //2、va_start(argp,msg)获取可变参数列表的第一个参数地址,此例即msg参数的地址; //arg 阅读全文
posted @ 2012-09-11 23:00 helloweworld 阅读(422) 评论(0) 推荐(0) 编辑
摘要: 函数名:vsnprintf原型:int _vsnprintf(char *buffer, size_t max_count, const char *format, va_list vArgList);功能:类同vsprintf,加了max_count限制。参数:返回值:如果成功调用此函数,返回写到buffer中的字符的个数(不包括结尾的'\0')。snprintf和vsnprintf函数不能够写多于size大小(包括结尾的'0')的字节数。如果输出因为以上原因被截断,返回成功写入buffer的字符数(不包括结尾的'\0'),如果有足够的内存空间 阅读全文
posted @ 2012-09-11 20:51 helloweworld 阅读(986) 评论(0) 推荐(0) 编辑
摘要: 函数:syslog()功能:记录至系统记录。头文件:#include <syslog.h>语法: int syslog(int priority, string message);返回值: 整数函数种类: 操作系统与环境内容说明 :本函数将 message 字符串写到系统纪录中,参数 priority 的值可能为 LOG_EMERG、LOG_ALERT、LOG_CRIT、LOG_ERR、LOG_WARNING、LOG_NOTICE、LOG_INFO、 LOG_DEBUG。本函数呼叫 UNIX 操作系统的 syslog() 函数,在 Windows NT 上,使用事件检视器模拟出本功 阅读全文
posted @ 2012-09-11 20:33 helloweworld 阅读(325) 评论(0) 推荐(0) 编辑
摘要: 在源代码中经常会出现下面一些错误处理函数。一、errno头文件:#include <errno.h>函数原型:errno功能:记录系统的最后一次错误代码参数:无返回值:错误代号(整型值)例子:1 2 3 4 5 if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { fprintf(stderr, "errno = %d \n", errno); exit(1); } printf("Socket opened successfully \n"); //errno 返回整型错误代号。 二、s 阅读全文
posted @ 2012-09-11 20:13 helloweworld 阅读(1690) 评论(0) 推荐(0) 编辑
摘要: 一、简介1、编译预处理命令均以#开头,以回车符结束;2、每条预处理命令独占一行;3、可以出现在程序的任意位置,但通常置于源程序的开始;4、在C++编译对源程序进行编译之前,先对程序中这些命令进行预处理;5、C++预处理主要有三种:文件包含、宏定义和条件编译。二、文件包含1、格式格式1:#include <filename>C++编译系统预定义的包含文件,这些文件在c++编译系统的include目录或其子目录中,通知预处理程序按系统规定路径检索文件。格式2:#include “filename”从当前工作目录开始查找,一般为自定义头文件。2、预处理程序对源文件进行扫描时,将产生一个临 阅读全文
posted @ 2012-09-11 15:28 helloweworld 阅读(535) 评论(0) 推荐(0) 编辑