当前位置:首页 » 《资源分享》 » 正文

C++系列8:常用库_kittyzc的博客

19 人参与  2021年05月09日 14:43  分类 : 《资源分享》  评论

点击全文阅读


1. cmath: 数学计算

#include <iostream>
#include <cmath>
using namespace std;
 
int main ()
{
   // 数字定义
   short  s = 10;
   int    i = -1000;
   long   l = 100000;
   float  f = 230.47;
   double d = 200.374;
 
   // 数学运算
   cout << "sin(d) :" << sin(d) << endl;
   cout << "abs(i)  :" << abs(i) << endl;
   cout << "floor(d) :" << floor(d) << endl;
   cout << "sqrt(f) :" << sqrt(f) << endl;
   cout << "pow( d, 2) :" << pow(d, 2) << endl;
 
   return 0;
}

下面是一个关于生成随机数的简单实例。实例中使用了cime的time()函数来获取系统时间的秒数,通过调用cstdlib的rand() 函数来生成随机数:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
srand( (unsigned)time( NULL ) );
for(int i = 0; i < 10; i++ )
   {
      // 生成实际的随机数
      int j= rand();
      cout <<"随机数: " << j << endl;
   }

如果使用相同的种子后面的rand()函数会出现一样的随机数。如:srand(1)
可以在宏定义中顶一个random(int number)函数:#define random(x)(rand()%x)

2. iomanip:格式化输出

#include<iostream>
#include<iomanip>

using namespace std;

int main(){
	double x=3.1415926;
	cout<<fixed<<setprecision(3)<<x<<endl;
	return 0;
}

3. nlohmann json:json解析

nlohmann/json 是一个用于解析json的开源c++库,口碑一流,号称有业界最好的性能,并且使用非常方便直观,是很多c++程序员的首选。
下载 https://github.com/nlohmann/json/tree/develop/single_include/nlohmann/json.hpp, 并加入本地工程。使用方式如下:
在这里插入图片描述

4. opencv:图像处理

这里直接用了openvino里面带的opencv。将其拷贝到3rdparty文件夹下,然后在CMakeLists中添加如下四行:
在这里插入图片描述
下面是使用例子:
在这里插入图片描述

5. openblas:矩阵计算

mac自带了openblas,在/usr/local/Cellar下。将其拷贝到项目文件夹下,在cmakelists里添加即可。
在这里插入图片描述
关于api的文档参照这里:
https://blog.csdn.net/weixin_43800762/article/details/87811697
首先是关键字:
在这里插入图片描述
接下来是:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


点击全文阅读


本文链接:http://zhangshiyu.com/post/18686.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1