代码改变世界

随笔档案-2015年03月

字节对齐

2015-03-26 15:11 by sylar_liang, 156 阅读, 收藏,
摘要: #define APR_ALIGN(size, boundary) / (((size) + ((boundary) - 1)) & ~((boundary) - 1))该宏目的为: 计算出最接近size的boundary的整数倍的整数.如:APR_AGLIN(7,4) = 8. 即 (7+3) &... 阅读全文

C++使用hash_map时警告

2015-03-20 14:07 by sylar_liang, 661 阅读, 收藏,
摘要: windows 与 linux 的头文件区别:#if defined(WIN32) || defined(WIN64) #include using namespace stdext;#else #include using namespace __gnu_cxx;#endif编译出现警告... 阅读全文

C++ 唯一实例类

2015-03-19 23:38 by sylar_liang, 1184 阅读, 收藏,
摘要: 通过Instance 来产生一个实例指针。使用:class ServerSessionFactory: public Singleton// Singleton.h: 唯一实例// 通过调用 Instance 来初始化得到唯一实例///////////////////////////////////... 阅读全文

makefile 示例1

2015-03-13 10:16 by sylar_liang, 229 阅读, 收藏,
摘要: # 设置编译器CC = g++# -fPIC 作用于编译阶段,告诉编译器产生与位置无关代码# -D宏定义,相当于C中的全局#define,可以通过宏定义来控制源程序的编译,例如:# #ifdef _FILELINE# printf("Hello Yu Qiang, How are you?\n");... 阅读全文

transform 函数测试

2015-03-11 18:01 by sylar_liang, 161 阅读, 收藏,
摘要: #include #include #include #include using namespace std;// 自定义泛函数template void PRINT_ELEMENTS(const T& coll, const char * str=""){ typename T::cons... 阅读全文

Stream_iterator 测试

2015-03-11 17:37 by sylar_liang, 172 阅读, 收藏,
摘要: #include #include #include #include #include // istream_iterator 与 ostream_iterator 头文件using namespace std;// 功能:// 1.从标准输入读取所有输入文字// 2.排序// 3.将它们打印到... 阅读全文

max_element 返回值上限与下限

2015-03-11 17:36 by sylar_liang, 421 阅读, 收藏,
摘要: #include #include #include using namespace std;//using namespace std::list;//using namespace std::cout;//using namespace std::endl;int main(int argc, ... 阅读全文

auto_ptr 用例1

2015-03-10 17:45 by sylar_liang, 154 阅读, 收藏,
摘要: auto_ptr // 头文件 std::auto_ptr ptr1(new ClassA); // okstd::auto_ptr ptr2 = new ClassA; // error 不允许 赋值(assign)初始化方式auto_ptr赋值会导致所有权的转移auto_ptr错误运用:1.au... 阅读全文

MySql 所遇到的问题及其解决方法

2015-03-09 15:18 by sylar_liang, 1029 阅读, 收藏,
摘要: 1.ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)>检查mysqld状态#/etc/rc.d/init.d/mysqld status如果是关... 阅读全文

mysql 数据库接口

2015-03-09 10:57 by sylar_liang, 3155 阅读, 收藏,
摘要: 一般步骤是:1.调用mysql_init()初始化MYSQL结构,许多的函数执行需要这个结构体。2.调用mysql_real_connect()连接数据库,参数中涉及到数据库名,数据库登录名,数据库密码等等。3.调用mysql_real_query()执行一条Select SQL语句,通过mysql... 阅读全文

mysql数据类型

2015-03-06 11:27 by sylar_liang, 246 阅读, 收藏,
摘要: 1.整型tinyint(m) 一个字节 -128~127smallint(m) 2个字节 -32768~32767mediumint(m) 3个字节 -8388608~8388607int(n) 4个字节bigint(n) 8个字节如果加了unsigned,则范围值翻倍。如tinyint unsig... 阅读全文

linux执行shell脚本

2015-03-06 00:09 by sylar_liang, 222 阅读, 收藏,
摘要: 方法有2种:1.bash myshell.sh2.先给脚本加上可执行权限。chmod +x myshell.sh./myshell.sh 阅读全文

mysql常用命令

2015-03-06 00:07 by sylar_liang, 167 阅读, 收藏,
摘要: 1.mysql服务的启动和停止启动: net stop mysql停止: net start mysql卸载: sc delete MySQL2.登陆mysqlmysql -h主机名 -u用户名 -p用户密码-h:该命令用于指定客户端所要登录的MySQL主机名, 登录当前机器该参数可以省略;-u:所... 阅读全文

CentOS 安装man man-pages

2015-03-05 17:32 by sylar_liang, 498 阅读, 收藏,
摘要: yum -y install man;yum -y install man-pages 阅读全文

inet_pton inet_ntop inet_aton htonl

2015-03-01 11:07 by sylar_liang, 336 阅读, 收藏,
摘要: #include #include #include #include // memory zero#include #include // AF_INET#include // inet_* 头文件#include // struct sockaddr_inint main(int arg... 阅读全文