时间函数: time_t T; time(&T); strftime(str, 255, "%Y-%m-%d %H:%M:%S", localtime(&T)); 获取当前时间 程序耗时:time_t begin; time($begin) difftime(time(NULL), begin); #include <time.h> clock_t start, end; double cpu_time_used; start = clock(); ... /* Do the work. */ end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; //return elapsed CPU time in microseconds double cpu_time() { return (double) clock() / CLOCKS_PER_SEC * 1e6; } 参数检查: int check_param(int argc, char **argv) { char stropt[] = "hes:i:o:l:"; int c; if (argc == 1) { print_usage(argv[0]); return -1; } while( (c = getopt(argc ,argv ,stropt)) != EOF) { switch(c) { case 's': sep=optarg; break; case 'i': infile=optarg; break; case 'o': outfile=optarg; break; case 'l': logfile=optarg; break; case 'h': print_usage(argv[0]); return -1; case 'e': g_daemon=1; break; default : cerr << "Error: unrecognized or incomplete command line." << endl; print_usage(argv[0]); return -1; } } return 0; } 计算数组大小: int c[] = {1,2,3,4}; for(int i = 0; i< sizeof(c)/sizeof(*c); i++) c[i]++ ; C++I/O cout << flush; //清空流 //把基数变为oct(八进制),dec(十进制)或hex(十六进制): cout << hex << "0x" << i << endl; //跳过空格 cin >> ws;