std unique 的实现

接触到 std 的 unique 这个函数,看了一下实现,自己也写了一下。在读默认的实现的时候发现代码真是的比较坑爹的,缩进啊,花括号啊,之类的,都是不按规范来的。 自己照着写了一个如下 #include <iostream> #include <vector> template<class It> It myUnique(It itBegin, It itEnd) { ……

阅读全文

c++ 模版类调用不同函数

我们都知道,c++ 用模版,可以根据不同的对象类型,生成不同的实际函数,但是,如果我想根据不同的条件,在一个模版类里面,调用不同的函数呢,能不能这样写 #include <iostream> using namespace std; void PrintA(int a) { cout<<a<<endl; } void PrintB(int b) { cout<……

阅读全文

strncpy 的用法

在官方的文档中,http://www.cplusplus.com/refer…,例程的 strncpy 的用法是: /* strncpy example */ #include <stdio.h> #include <string.h> int main () { char str1[]= "To be or not to be"; char str2[40]; char str3[40]; /* copy to size……

阅读全文

Linux TCP UDP 混合

基本的思路是这样的:在服务器端,有两个机器,一个对外开启 TCP 监听,然后把监听到的请求内容送到后面的另外一台,或者多台轮询机器上,内网之间使用 UDP,然后等待业务逻辑机器处理完成,这个地方可以做成异步的,然后再返回到用户。 即是这样: client server_front server_back 下面来看代码,首先是 server_f……

阅读全文