C++
xxxx追风
迷茫与混乱在于不知其本质与起源,道生一,一生二,二生三,三生万物。
展开
-
C/C++ 中 static 的用法全局变量与局部变量
C/C++ 中 static 的用法全局变量与局部变量我是传送门原创 2022-05-15 22:28:26 · 303 阅读 · 0 评论 -
C++中将string类型转化为int类型
C++中将string类型转化为int类型 把 string 型,转为int型#include <iostream>#include <string.h>#include <stdlib.h>using namespace std;int main(){ string a="11",b="22"; cout<<atoi(a)+atoi(b)<<endl; return 0;}#include <iostre原创 2022-04-15 21:18:52 · 10839 阅读 · 0 评论 -
linux内存泄漏检测valgrind
valgrind 检查内存泄漏 Linux 下1、安装sudo apt-get install valgrind2、使用先用qt或者g++对代码编译然后对编译后的文件生成可执行程序test之后,如何使用Valgrind来生成内存的记录文件呢?一般这样使用:valgrind --leak-check=full --log-file=test_valgrind.log --num-callers=30 ./test–log-file 后面的test_valgrind.log是指定生成的日志文原创 2022-03-23 15:37:13 · 2544 阅读 · 0 评论 -
c++类型转换详解
c++ const_cast;#include<iostream>using namespace std;int main(){//c++ const_cast;const int a = 10 ;int* pA = &a; }不能讲一个常量直接赋值给一个int 类型demo1.cpp: In function ‘int main()’:demo1.cpp:7:11: error: invalid conversion from ‘const int*’ to ‘原创 2022-03-07 12:43:00 · 719 阅读 · 0 评论 -
weak_ptr 使用场合
weak_ptr 使用场合weak_ptr只能从shared_ptr对象构建,或者从另外一个weak_ptr获取。weak_ptr并不影响动态对象的生命周期,即其存在与否并不影响对象的引用计数器。当weak_ptr所指向的对象因为shared_ptr计数器为0而被释放后,那么weak_ptr的lock方法将返回空。weak_ptr并没有重载operator->和operator *操作符,因此不可直接通过weak_ptr使用对象。提供了expired()与lock()成员函数,前者用于判断w原创 2022-03-05 21:29:44 · 427 阅读 · 0 评论 -
面向对象的抽象法则--c++的viture实现原理
面向对象的抽象法则面向对象的设计在与在原有类的基础之上对原有类进行扩展如下,我们定义Shape基类,希望可以用circle,squre,来继承基类,#include<iostream>using namespace std;class Shape{public: double Area() const { return 0; } void Display() { cout << Area() << endl; }};class Squre原创 2022-02-23 19:23:14 · 431 阅读 · 0 评论 -
C++保留有效位与保留小数位
C++保留有效位与保留小数位c++怎么保留有效数字呢?#include<iostream>#include<cmath>using namespace std;int main(){double a = 1.555555;a = floor(a*pow(10, 3))/pow(10, 3);cout << a << endl;}C语言中的floor函数示例如下:#include <math.h>#include <原创 2022-02-07 21:53:10 · 1431 阅读 · 0 评论 -
ubuntu安装c++手册,cppman查看
ubuntu安装c++手册,cppman查看sudo add-apt-repository ppa:aitjcize/manpages-cppsudo apt-get updatecppman -csudo apt install cppmancppman std::string原创 2022-02-01 18:46:20 · 1796 阅读 · 0 评论