C++基础
记录c++学习过程中的基础知识
Zero_to_zero1234
Be objective
展开
-
c++耗时测试
c++耗时测试#include<time.h> using namespace std; int TestTimeCost(){ clock_t startTime,endTime; startTime = clock(); for (int i = 0; i < 1000000; i++) { i++; } endTime = clock(); cout << "Totle Time : " <<(double)(endTime -原创 2020-05-28 17:21:26 · 774 阅读 · 0 评论 -
Linux下,c++获取当前程序路径
Linux下,c++获取当前程序路径#include <stdio.h>#include <unistd.h>char *buffer;buffer = getcwd(NULL, 0);cout << "文件路径" << buffer << endl;//将需要调用的模块使用 strcat 作拼接;const char *model_path = strcat(buffer,"/models");或者:#include <原创 2020-05-28 16:26:08 · 6193 阅读 · 0 评论 -
对‘pthread_create’未定义的引用
Linux中,对‘pthread_create’未定义的引用 bug 问题解决办法:由于pthread库不是Linux系统默认的库,连接时需要使用库libpthread.a,所以在使用pthread_create创建线程时,在编译中要加-lpthread参数:gcc -o pthread -lpthread pthread.c如果还不对,很有可能是-lpthread放置的位置不对:gcc pthread.c -lpthread -o pthread...转载 2020-05-28 14:14:53 · 10453 阅读 · 4 评论 -
windows中vscode 配置 C/C++ 编译环境 教程
参考博客: https://blog.csdn.net/qq_43041976/article/details/100542557,–(2020年05月26日亲测可行)–原创 2020-05-27 01:35:58 · 532 阅读 · 0 评论 -
引用做函数的返回值
#include<iostream>#include<string>using namespace std;//引用做函数的返回值//引用的注意事项//1、不要返回局部变量的引用//2、函数的调用可以作为 左值// static c = 100;int& test01(){ int a = 10; //局部变量存放在四区中的 栈区 return a;}int& test02() //{ static in原创 2020-05-22 12:04:08 · 233 阅读 · 0 评论 -
C/C++ 中 static 的用法
C/C++ 中 static 的用法什么是static?static 是 C/C++ 中很常用的修饰符,它被用来控制变量的存储方式和可见性。1.1 static 的引入我们知道在函数内部定义的变量,当程序执行到它的定义处时,编译器为它在栈上分配空间,函数在栈上分配的空间在此函数执行结束时会释放掉,这样就产生了一个问题: 如果想将函数中此变量的值保存至下一次调用时,如何实现? 最容易想到的方法是定义为全局的变量,但定义一个全局变量有许多缺点,最明显的缺点是破坏了此变量的访问范围(使得在此函数中定义原创 2020-05-22 11:56:16 · 509 阅读 · 0 评论 -
函数的多种传参方式与区别
函数的多种传参方式与区别1、值传递,形参不会修饰实参2、地址传递,形参会修饰实参3、引用传递,形参会修饰实参#include<iostream>#include<string>using namespace std;//1、引用:给变量起别名//语法: 数据类型 &别名 = 原名//引用的注意事项//1、引用必须要初始化 int &b = a;//2、引用一旦初始化后,就不可以更改了void mySwap01(int a, int b)原创 2020-05-22 11:30:04 · 1137 阅读 · 0 评论 -
C++ 传递数组给函数
C++ 传递数组给函数:C++ 传数组给一个函数,数组类型自动转换为指针类型,因而传的实际是地址。也就是说遍历函数中数组参数,实际上是遍历实参,而且也会改变外部实参# include<iostream># include<string>using namespace std;struct Hero{ // 姓名 string name; //年龄 int age; //性别 string sex;};void原创 2020-05-21 15:24:21 · 2482 阅读 · 0 评论 -
Ubuntu18.04下配置VScode的C/C++开发环境
推荐Ubuntu16.04下配置VScode的C/C++开发环境:,亲测(2020.05.13)也可用转载 2020-05-14 18:24:36 · 6495 阅读 · 3 评论