如何在 Linux 上用 C++ 安装 Boost 库?
Boost是一组用于 C++ 编程语言的库。它包含164 个独立的库。它最初于1999 年 9 月 1 日发布。此外,它还支持许多任务,例如伪随机数生成、线性代数、多线程、图像处理、正则表达式和单元测试。在本文中,我们将学习如何在 Linux 上使用 C++ 安装 boost 库。
在 Linux 上用 C++ 安装 Boost 库:
方法一:使用apt-get命令:
要在 Linux 上安装 boost 库,请在 Linux 终端中运行以下命令。
sudo apt-get install libboost-all-dev
![在 Linux 上使用 apt-get 命令在 C++ 中安装 Boost 库](https://mangodoc.oss-cn-beijing.aliyuncs.com/geek8geeks/How_to_Install_Boost_Library_in_C++_on_Linux?_0.jpg)
安装boost库
按关键字中的y确认安装。这将确认用户想要安装上面列出的包。
为了验证安装,让我们使用 boost 库运行一个示例程序。
在这个示例程序中,我们将使用 boost 库创建一个数组。为此,我们必须将 boost 的数组头文件包含到我们的 CPP 程序中。
代码:
C++
#include
#include
using namespace std;
int main()
{
boost::array arr
= { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } };
for (int i = 0; i < 10; i++) {
cout << "Geek Rank is :" << arr[i] << "*"
<< "\n";
}
return 0;
}
输出
Geek Rank is :1*
Geek Rank is :2*
Geek Rank is :3*
Geek Rank is :4*
Geek Rank is :5*
Geek Rank is :6*
Geek Rank is :7*
Geek Rank is :8*
Geek Rank is :9*
Geek Rank is :10*