随笔分类 -  c & c++

Linux 下获取本机IP
摘要:http://blog.csdn.net/K346K346/article/details/48231933 /*//设置为本机IP,如果获取地址失败则使用hostname,这种获取方式依赖/etc/hosts,获取不准。 // 获取本机地址,只取一个 hostent* pHost = gethos 阅读全文

posted @ 2018-03-01 09:57 偏爱省略号 阅读(2012) 评论(0) 推荐(0)

long 与int 比较问题
摘要:long 与int 比较,在32位机器,sizeof都是 占用4个字节; 在window 64位也是占用4个字节 但是在Linux 64位,long占用 8个字节, int占用4个字节,这样比较就会有问题。 当int 强转 位long时,发生 int高位1(符号位1)转为long的高位1(补全) 出 阅读全文

posted @ 2017-06-02 09:11 偏爱省略号 阅读(8180) 评论(0) 推荐(0)

linux 中文输出
摘要:#include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 int main() 10 { 11 std::basic_ifstream > fs("./test.txt"); 12 if ( fs.fail() ... 阅读全文

posted @ 2017-05-18 15:52 偏爱省略号 阅读(204) 评论(0) 推荐(0)

mmap
摘要:mmap, munmap - map or unmap files or devices into memory #include void *mmap(void *addr, size_t length, int prot, int flags, ... 阅读全文

posted @ 2015-06-11 16:01 偏爱省略号 阅读(354) 评论(0) 推荐(0)

Thread-local storage (TLS)
摘要:线程存储原理:为变量在每一个现存的线程里分配一个实例,需要处理器支持,并不是所有都支持!支持全局的,静态的变量,但不支持局部变量。关键字 __thread __thread int i; extern __thread struct state s; static __thread cha... 阅读全文

posted @ 2014-11-10 15:50 偏爱省略号 阅读(350) 评论(0) 推荐(0)

getopt
摘要:int getopt(int argc, char * const argv[], const char *optstring);1.getopt() 用来解析命令行参数。程序启动时,argc,argv两个参数传递给运行程序,argv里的参数项以'-'(或'--')开始。循环调用getopt(),将... 阅读全文

posted @ 2014-09-24 17:25 偏爱省略号 阅读(544) 评论(0) 推荐(0)

printf
摘要:manual:http://man7.org/linux/man-pages/man3/printf.3.html int printf(const char *format, ...); 通过format格式串控制输出,调用成功返回输出字符个数(不包括null);失败返回负值。 char ... 阅读全文

posted @ 2014-09-17 11:04 偏爱省略号 阅读(286) 评论(0) 推荐(0)

scanf
摘要:manual:http://man7.org/linux/man-pages/man3/scanf.3.htmlhttp://www.cnblogs.com/jcss2008/archive/2008/09/20/1294905.htmlint scanf( const char *format, ... 阅读全文

posted @ 2014-09-15 18:04 偏爱省略号 阅读(594) 评论(0) 推荐(0)

The GNU C Library
摘要:Any Unix-like operating system needs a C library: the library which defines the ``system calls'' and other basic facilities such as open, malloc, pr... 阅读全文

posted @ 2014-08-22 17:03 偏爱省略号 阅读(234) 评论(0) 推荐(0)

C standard library
摘要:Fromwikipedia TheC standard libraryis thestandard libraryfor theC programming language, as specified in theANSI Cstandard.[1]It was developed at th... 阅读全文

posted @ 2014-08-22 16:07 偏爱省略号 阅读(628) 评论(0) 推荐(0)

linux 检测进程是否存在
摘要:1. 直接遍历/proc目录 int find_pid_by_name( char* pidname, pid_t *pidlist){#define READ_BUF_SIZE 256 DIR *dir; struct dirent *next; int i = 0; ... 阅读全文

posted @ 2014-07-07 09:55 偏爱省略号 阅读(721) 评论(0) 推荐(0)

curl 编译
摘要:curl是利用URL语法在命令行方式下工作的开源文件传输工具。它被广泛应用在Unix、多种Linux发行版中,并且有DOS和Win32、Win64下的移植版本。支持很多协议:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 LDAP。样支持... 阅读全文

posted @ 2014-05-04 17:12 偏爱省略号 阅读(513) 评论(0) 推荐(0)

str_replace字符串替换
摘要:字符串替换, src 源字符串, buf_size 缓冲大小, search搜索的字符串大小, repstr 需要替换成的字符串int str_replace(char *src, unsigned int buf_size, char* search, char *repstr){ if(!src... 阅读全文

posted @ 2014-04-29 18:07 偏爱省略号 阅读(503) 评论(0) 推荐(0)

mutable c++
摘要:The keyword mutable is used to allow a particular data member of const object to be modified. This is particularly useful if most of the members sho... 阅读全文

posted @ 2014-04-24 15:36 偏爱省略号 阅读(219) 评论(0) 推荐(0)

printf("%d \n", -1 < sizeof(int) ) Implicit conversion
摘要:int i = -1;printf("%d \n", -1 < sizeof(int) );结果输出: 0 在写程序时,经常对于比较很随意,特别是类型不同时,然而这带来的错误也是意想不到,却理所当然。剖析:sizeof(int) 结果返回unsigned int ,值为4i是int类型, int 与... 阅读全文

posted @ 2014-04-14 20:15 偏爱省略号 阅读(607) 评论(0) 推荐(0)

导航