一、安裝
剛剛使用linux系統,對很多系統命令和操作方式還不是很熟悉。想裝個boost庫,在網上看了幾篇教程根本沒弄明白,終於,用三行命令解決了。
yum install boost
yum install boost-devel
yum install boost-doc
二、使用
對於我這樣的小白來說,使用動態鏈接庫時要添加鏈接我是不知道的,后來也是自己慢慢摸索出來了。
首先測試頭文件。
- #include <iostream>
- #include <boost/filesystem.hpp>
- int main()
- {
- std::cout<<"hello,world"<<std::endl;
- return 0;
- }
使用g++ test.cpp -o test 編譯 ./test 執行
再測試需要用到二進制庫的功能模塊
- #include <iostream>
- #include <boost/filesystem.hpp>
- using namespace boost::filesystem;
- int main(int argc, char *argv[])
- {
- if (argc < 2) {
- std::cout << "Usage: tut1 path\n";
- return 1;
- }
- std::cout << argv[1] << " " << file_size(argv[1]) << std::endl;
- return 0;
- }
注意:這時我使用的是g++ test.cpp -o test -lboost_system -lboost_filesystem
執行 ./test, 輸出
Usage: tut1 path
恭喜你,成功了!