![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c\c++
AllBull
致力于精通C++,向着元宇宙进军
致力于六边形战士
展开
-
c++中三种传参方式
//值传递void mySwap01(int a,int b) { int temp = a; a = b; b = temp;}//地址传递void mySwap02(int* a, int* b) { int temp = *a; *a = *b; *b = temp;}//引用传递void mySwap03(int& a, int& b) { int temp = a; a = b; b = temp;}void test003() { i.原创 2022-01-13 11:13:20 · 139 阅读 · 0 评论 -
通讯录-c语言实现
使用的技术:函数数组指针IO读写#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>#include <string.h>#include <stdlib.h>#include <errno.h>//#define MAX 100#define SIZE_NAME 20#define DEFAULT_SZ 3 //默认初始化大小#define ADD_SZ 2 //每次扩容.原创 2022-01-11 11:56:07 · 194 阅读 · 0 评论 -
指针和引用的使用
引用简化了操作struct Person01 { int age;};void allocateSpace1(Person01** p) { //p 二级指针指向*p *p 是指针指向 Person **p是 Person *p = (Person01*)malloc(sizeof(Person01)); (*p)->age = 10;}void allocateSpace2(Person01* &p) { p = (Person01*)malloc(si.原创 2022-01-13 11:48:08 · 111 阅读 · 0 评论 -
C++中函数重载 【引用+const】 的两个版本
此两个函数可以同时存在,但是不可以重载一个函数:void myFunc801(int a) ;这三个不能重载,会有二义性。对于以下代码:传参的时候,如果传的是数字10,调用的是const修饰的,传的变量a,调用的是int&a。int &a = a;const int& a = 10;void myFunc801(int& a) { cout << "myfunc(int &a) invoke" << endl;}原创 2022-01-13 13:47:48 · 458 阅读 · 0 评论 -
在c++中使用c文件
version1:使用extern “C”.cpp如下:#include<iostream>using namespace std;extern "C" void testc();//在cpp中存在函数重载,会将testc修饰为_Z4testcv;无法链接,所以使用extern "C" void testc();//使用C语言的方式取链接testcvoid test01() { cout << "this is .cpp" << endl; t原创 2022-01-13 14:27:30 · 784 阅读 · 0 评论 -
C++ 封装一个简单的String
大体都完成了,剩余对类的 () 重载 仿函数 的实现有bug。其余正常运行。.h文件:#pragma once#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;class MyString { //友元 friend ostream& operator<<(ostream& cout, MyString& str); friend is..原创 2022-01-14 22:26:48 · 224 阅读 · 0 评论 -
c++谓词的使用,仿函数在sort的表达形式
sort(v.begin(), v.end(), greater<int>()); sort(v.begin(), v.end(), less<>()); sort(v.begin(), v.end(), greater<>{});#include <iostream>#include <algorithm>using namespace std;#include <string>#i...原创 2022-01-20 22:36:01 · 496 阅读 · 0 评论 -
Linux中制作c静态库 及其 优缺点
1.建立项目的结构:2.编写程序:3.编译为obj文件4.打包为静态库 并移动到lib文件中5.此时只使用include中的接口和 lib中的静态库 ,即可:编写测试类main:编译并运行:-----注意:静态库的命名格式为 lib +名称+ .a调用静态库的方式:1. -L lib (库目录) -l MyCalc (名称)2. main.c lib/libMyCalc.a此时打包发送 ...原创 2022-01-25 20:53:16 · 1177 阅读 · 0 评论 -
Linux中制作c动态库(共享库) 及其 优缺点
动态库命名:lib+ 名称 + .so静态库命名:lib+ 名称 + .a(接静态库)1.生成与位置无关的obj文件2.生成共享库 移动 到 lib中3.测试同样也可以使用这种方式:(避免和静态库重复二义)方式1.这种方式要配置 将 动态库移动到 /lib中(不推荐)方式2.将动态库 放到 LD_LIBRARY_PATH中export LD_LIBRARY_PATH=./lib这个是临时的测试导入到环境中。如果要永久设置,可...原创 2022-01-25 21:47:36 · 1251 阅读 · 0 评论 -
Makefile 的 简单入门
#calc:main.c add.c sub.c mul.c div.c #命令 #gcc main.c add.c sub.c mul.c div.c -o calc #-----------------------------------#makefile有多条规则时,默认第一条为最终的规则,其他为第一条服务#此编译只会编译改动过的文件#calc:main.o add.o sub.o mul.o div.o #gcc main.o add.o sub.o mul.o div.o .原创 2022-01-26 14:42:26 · 280 阅读 · 0 评论 -
查看linux文件目录数 :opendir
#include <sys/types.h>#include <stdio.h>#include <stdlib.h>#include <dirent.h>#include <string.h>int getFileNum(char* root){ //open DIR* dir = NULL; struct dirent* ptr = NULL; char path[1024] = {0}; int count = 0;.原创 2022-01-26 21:52:11 · 168 阅读 · 0 评论 -
makefile编译 同目录中的 .c 为 同名可执行文件
CFLAGS = -g -Wall -WerrorLDFLAGS = -lpthreadsrc = $(wildcard *.c)target = $(patsubst %.c, %, ${src}).PHONY: all clean%.o:%.c $(CC) ${CFLAGS} -c -o $@%:%.o $(CC) ${LDFLAGS} -o $@all: ${target}clean: rm -f ${target}CFLAGS = -g -W...原创 2022-01-27 17:14:35 · 927 阅读 · 0 评论 -
linux系统编程:将进程信息写入到文件中
#include <unistd.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>int main(){ int fd; fd = open("ps.txt",O_WRONLY|O_CREAT|O_TRUNC,0644); if(fd < 0){ perror("open file"); exit(1); }...原创 2022-01-27 18:45:49 · 1770 阅读 · 0 评论 -
linux-pipe通信实现 ps aux | grep [key]
/* 使用pipe完成 ps aux | grep bash ************************************************************************/#include <sys/wait.h>#include <sys/types.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <s.原创 2022-01-27 22:58:16 · 1021 阅读 · 0 评论 -
利用pipe实现兄弟进程之间的通信
/* 使用pipe完成 ps aux | grep bash ************************************************************************/#include <sys/wait.h>#include <sys/types.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <s.原创 2022-01-27 23:53:25 · 151 阅读 · 0 评论