- 博客(62)
- 收藏
- 关注
原创 面向 对象 编程
#include <iostream> using namespace std; // 面向 对象 编程 // 实现通讯录: // 面向过程:有哪些功能:增加用户、删除用户、修改、查找..... // 面向对象:通讯录实现有哪个东西(对象) --> 用户、用户管理(操作用户:加用户、删除用户、修改、查找.....) // ===> 一个场景 场景的东西(对象) ...
2019-01-18 19:41:12
187
原创 c++新增特性
// C++11 新增特性 // 1、自动类型推导 ====> auto int main1() { auto a = 10; // a 是 int 类型 auto d = 1.2; // d 是 double 类型 auto f = 2.3; // f 是 float 类型 cout << a << d <<...
2019-01-18 19:36:36
259
原创 动态内存分配
#include <iostream> #include <stdlib.h> using namespace std; // 动态内存分配 // 1、c中 使用 malloc 和 free ===> 库函数 不是语法的一部分 // 2、C++中 使用 new 和 delete ===> 运算符(+、-、*...) 是语法的一部分 // str...
2019-01-16 21:22:21
129
原创 内联函数
#include <iostream> using namespace std; // define // 1、定义常量 宏常量 ==> 建议 const 进行替换 // 2、定义函数 宏函数 ==> 建议 内联函数 进行替换 #define MAX(a,b) a>b?a:b #define ADD(a,b) ((a)+(b)) //...
2019-01-16 21:21:42
186
原创 引用
#include <iostream> using namespace std; // 1、引用的概念 // 引用:空间的别名 // 类型 &别名 = 其他变量 int main1() { // a 是变量名, 代表一个4字节的空间 int a = 10; // b 是 a 所代表的的空间的别名 // b 和 a 代表的是同一块空间 ...
2019-01-16 21:20:32
164
原创 const修饰
#include <iostream> using namespace std; // C++中的const修饰的是一个常量: // 1、const常量正常情况下内存不会为其分配空间,而是存在符号表中 // 2、使用的时候去符号表中取值你 // 3、如果对 const 常量进行取地址操作,则编译器会为其分配一块空间,但是 它本身并不会使用 int main1() { con...
2019-01-16 21:16:38
171
原创 函数重载
#include <iostream> using namespace std; // 函数重载:同一个函数名,可以有多个不同的实现 void myPitnt(int a) { printf ("a = %d\n", a); } void myPitnt(const char *pstr) { printf ("str = %s\n", pstr); } // ...
2019-01-16 21:15:28
149
原创 c++标准输入输出
// C++ 的标准输入输出头文件 input output stream #include <iostream> using namespace std; // 标准输出 int main1() { // cout 类似于 printf, 作用是往屏幕打印数据 // 区别:cout 是个变量 printf 是个函数 // << : 左移操...
2019-01-16 21:14:25
821
原创 c++命名
#include <stdio.h> #include <cstdio> // 命名空间的定义:定义一块命名空间,名字叫 NameA namespace NameA { // 原来全局空间可以做的事情,命名空间都可以做:定义变量、函数、宏、结构体、枚举.... int g_a; int g_b; int add(int a, int b...
2019-01-16 21:13:18
374
原创 聊天室基础功能实现
客户端 Client.c #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> #include <arpa/inet.h> #include <string.h> #include <unistd.h&g...
2019-01-10 20:15:34
303
原创 聊天室登陆篇
Server.c #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> #include <arpa/inet.h> #include <string.h> #include <unistd.h> #...
2019-01-08 23:43:00
243
原创 聊天室登陆功能
服务器 main.c #include <stdio.h> #include <unistd.h> #include <pthread.h> #include "Server.h" int main(int argc, char **argv) { int listen_socket = init(); if (-1 == listen_socke...
2019-01-07 21:11:08
434
原创 并发网络编程-进程和线程
#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/socket.h&gt; #include &lt;arpa/inet.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&am
2019-01-07 21:03:44
187
原创 线程
线程创建 #include <stdio.h> #include <pthread.h> // 线程的工作函数 void *worker(void *v) { long num = (long)v; while (1) { printf ("子线程: %ld\n", num); sleep(1); } } int main() { // 1、创建的...
2019-01-04 19:13:23
102
原创 sqlite3
数据库操作 #include &lt;stdio.h&gt; #include &lt;sqlite3.h&gt; int main() { sqlite3 *db; int ret = sqlite3_open("student.db",&amp;db); if(ret != SQLITE_OK) { printf("数据库打开失败\
2019-01-03 21:07:37
151
原创 服务器,客户端
一个服务器,开两个客户端,客户端发信息给服务器,服务器收到后给客户端发送消息的大写版本 tcp客户端 #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> #include <arpa/inet.h> #include &l...
2019-01-02 20:25:16
161
原创 生产者与消费者模型两例
1 #include <stdio.h> #include <pthread.h> #include <semaphore.h> #include <string.h> #include <time.h> struct msg { char buf[20]; sem_t full; sem_t empty; }data; /...
2018-12-28 19:49:10
127
原创 线程
创建线程 #include <stdio.h> #include <pthread.h> void *worker (void *v ) { long num = (long)v; while(1) { printf("子线程: %ld\n",num); sleep(1); } } int main() { pthread_t thread; in...
2018-12-27 20:43:09
171
1
原创 卖票系统
semaphor.h #ifndef __SEMAPHORE_H__ #define __SEMAPHORE_H__ #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> #include <string.h> union semun { int ...
2018-12-26 23:04:33
248
原创 管道
管道 #include <stdio.h> #include <unistd.h> int main() { int pipefd[2]; // 0 读端 1 写端 int ret = pipe(pipefd); if (-1 == ret) { perror("创建管道失败\n"); return -1; } write(pipefd[...
2018-12-25 22:47:17
93
原创 进程
fork用法 #include <stdio.h> #include <sys/types.h> #include <unistd.h> int count = 0; int main1() { // 创建子进程 // 返回值:1、在父进程中返回子进程的pid 2、在子进程中,返回0 // 创建成功以后,子进程和父进程的执行顺序是不固定的 pid_...
2018-12-24 23:32:46
81
原创 九大排序(二)
5、二分法插入排序 void mySwap(int *a,int i,int j) { int tmp=a[i]; a[i]=a[j]; a[j]=tmp; } void mySort(int *a,int len) { int i,j,get; for(i=1;i<len;i++) { get=a[i]; int left=0; int right=i-1; ...
2018-12-19 22:59:39
98
原创 二叉树
BTree.h #ifndef _BTREE_H_ #define _BTREE_H_ typedef enum{FALSE, TRUE} BOOL; typedef enum{LEFT, RIGHT} MOUNTWAY; typedef char BTreeData; typedef struct btreeNode // 二叉树的结点 { BTreeData dat...
2018-12-17 23:06:15
128
原创 停车场
Stack.h #ifndef _STACK_H_ #define _STACK_H_ #define SIZE 10 typedef enum {FALSE, TRUE} BOOL; //顺序栈--------------------------------------- typedef struct data { char plate[10]; int t_year; in...
2018-12-14 21:16:59
187
原创 栈+队列
顺序栈 Static.h #ifndef _STACK_H_ #define _STACK_H_ #define SIZE 10 typedef enum {FALSE, TRUE} BOOL; typedef int Data; typedef struct stack { Data data[SIZE]; // 栈存储空间 int top; // 栈顶元素的下标 ...
2018-12-11 18:29:10
105
原创 链表
单向循环链表 LinkList.h #include <stdio.h> #include "LinkList.h" int main() { List *ls = CreateList(); if (NULL == ls) { printf ("创建失败\n"); } printf ("创建成功\n"); int i; for (i = 0; i < 1...
2018-12-10 21:04:23
103
原创 链表4题
找倒数第k个结点 main.c #include &amp;lt;stdio.h&amp;gt; #include &quot;LinkListtask.h&quot; int main() { List *ls = CreateList(); if (NULL == ls) { printf (&quot;创建链表失败\n&quot;); } printf (&am
2018-12-10 00:21:48
142
原创 链表
LinkList.h #ifndef _LINKLIST_H_ #define _LINKLIST_H_ typedef enum {TRUE, FALSE, ERROR} BOOL; typedef int Data; typedef struct _node { Data data; // 数据域 struct _node *next; // 指针域 }Node;...
2018-12-08 00:07:15
83
原创 顺序表
main.c #include <stdio.h> #include "Seq.h" int main() { Seq *s = Create(); if (NULL == s) { printf ("创建顺序表失败\n"); } printf ("创建顺序表成功\n"); int i; for (i = 0; i < 18; i++) { ...
2018-12-07 00:24:45
86
原创 c语言深度剖析笔记
union 声明联合数据类型 enum 声明枚举类型 static 声明静态变量 register 声明寄存器变量 const 声明只读变量 volatile 说明变量在程序执行中可被隐含地改变 typedef 用以给数据类型取别名(当然还有其他作用) extern 声明变量是在其他文件中声明(也可以看作是引用变量) 定义:编译器创建一个对象,为这个对象...
2018-12-06 00:37:19
223
原创 Makefile
Makefile 在当前文件下生成 src = $(wildcard *.c) obj = $(patsubst %.c, %.o, $(src)) target = a.out all:$(target) $(target) : $(obj) gcc $(obj) -o a.out main.o:main.c gcc -c main.c -o main.o add.o:add.c...
2018-12-05 00:34:46
98
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅