IP协议头详解

IPv4 (1) 版本:占4位,指IP协议的版本。通信双方使用的IP协议的版本必须一致。目 前广泛使用的IP协议版本号为4 (即IPv4)。 (2) 首部长度:占4位

UDP协议详解

概述 用户数据报协议UDP只在IP的数据报服务之上增加了很少一点的功能,这就是复用和 分用的功能以及差错检测的功能。UDP的主要特点是: UDP是

IP协议详解

IP协议概述 网际协议IP是TCP/IP体系中两个最主要的协议之一[STEV94][COME06][FORO10],也 是最重要的因特网标准协议

algorithm库操作总结

非修改序列操作 for_each 1 2 template <class InputIterator, class Function> Function for_each (InputIterator first, InputIterator last, Function fn); 1 2 3 4 5 6 7 8 9 template<class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function fn) { while (first!=last) { fn (*first); ++first; } return fn; // or, since C++11: return move(fn); } all_of 1 2 3 4 5 6 7 8 9

#pragma 预处理指令浅析

功能 在所有的预处理指令中,#pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作。 #pragma指

C语言程序可以没有main函数

几乎所有程序员的第一堂课都是学习helloworld程序,下面我们先来重温一下经典的C语言helloworld。 1 2 3 4 5 6 7 /* hello.c */ #include <stdio.h> int main()

C++ 中头文件(.h)和源文件(.cc)

头文件的作用 头文件的作用主要表现为以下两个方面: 通过头文件来调用库功能。出于对源代码保密的考虑,源代码不便(或不准)向用户公布,只要向用户提

math库数值处理函数总结

向上取整ceil() double ceil (double x); float ceil (float x); long double ceil (long double x); double ceil (T x); // additional overloads for integral types 向上取整,返回大于等于x的值. 示例: 1 2 3 4 5 6 7 8 9 10 11 #include <stdio.h> /* printf */#include <math.h> /*

scanf()和sscanf()详解

函数原型 int sscanf( string str, string fmt, mixed var1, mixed var2 ... ); int scanf( const char *format [,argument]... ); 返回值 一般使用scanf函数时都是为某个变量赋值,不考虑它的返回值。但是任何函数都是需要返回的

map排序相关讨论

map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value。假如存储学生和其成绩(假

哈弗曼树详解

一、哈夫曼树的定义 什么是哈夫曼树? 让我们先举一个例子。 判定树: 在很多问题的处理过程中,需要进行大量的条件判断,这些判断结构的设计直接影响着程

Singleton的相关实现

单线程 在单线程下,下面这个是常见的写法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 template<typename T> class Singleton { public: static T& getInstance() { if (!value_) { value_ = new T(); } return *value_; } private: Singleton(); ~Singleton(); static T* value_; };

string与其他类型间的转换

string与char数组的转换 string转char数组 使用c_str函数 string a="hello world"; const char* ch=a.c_str(); 注意: c_str函数的返回值是const char*的

unordered_map操作总结

构造函数 empty (1) explicit unordered_map ( size_type n = /* see below */, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& alloc = allocator_type() ); explicit unordered_map ( const allocator_type& alloc ); range (2) template <class InputIterator> unordered_map ( InputIterator first, InputIterator last, size_type n = /* see below */, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& alloc