What is the boost library
In short, the Boost library is some of the extensions to the C + + language standard library C++ The general name of the program library is developed and maintained by the Boost community organization. The Boost library works perfectly with the C + + standard library and provides extend Function.
Many features of C + + 11 and C + + 14 come from the boost library. Many boost libraries adopt the style of STL and need the foundation of STL. It is recommended to use STL well before looking at boost.
boost, to be more precise, is not a library, but a collection of libraries. Not everyone. You should quickly read some introductions first. You only need to know what libraries there are and what each library does. Then, when you encounter problems, take a closer look at the specific library usage.
For more details, see the following links:
Boost library - Baidu Encyclopedia
Is it necessary to learn the boost library to learn C + +- Know
Download and installation of boost library
download
Some online tutorials waved to the boost official website to download. Originally, I thought it would be good to download from the official website. However, after clicking the download on the official website, I actually jumped to a JFrog website. I had to install JFrog related supporting environment to download the boost library I needed from JFrog. What? It's big to think about. I can bypass it.
I recommend the following two links. Download the compressed package directly, and then configure it according to the relevant tutorials. It's much more convenient.
Download address of each version of Boost library
I used the second one.
install
I downloaded boost_1_77_0
Unzip the file and open it to the root directory of the boost library:
Double click the bootstrap.bat file to generate b2.exe, then open b2.exe and enter the following command in cmd:
Bjam -- toolset = MSVC -- build type = complete stage, and then enter
Waiting for the program to compile takes about ten minutes to two hours. Two folders, bin.v2 and stage, will be generated in the root directory of boost. Among them, bin.v2 is the generated intermediate file with a size of about 2.2G, which can be deleted directly. The generated dll and lib files are under stage.
VS Project attribute configuration (VS2019)
Project - > Properties
In the pop-up Properties dialog box:
Configuration attribute - > VC + + Directory: "include directory": the root directory of boost, for example: D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0
"Library Directory": the link library directory under the stage, for example: D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0\stage\lib
Configuration properties - > linker - > General: "additional library directory": the same as the above "Library Directory", for example: D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0\stage\lib
So far, the environment has been configured. Let's test it:
Click to view the code#include <cstdlib> #include <iostream> #include <vector> #include <iterator> #include <algorithm> #include <boost/timer.hpp> #include <boost/progress.hpp> #include <libs/date_time/src/gregorian/greg_names.hpp> #include <libs/date_time/src/gregorian/greg_month.cpp> #include <libs/date_time/src/gregorian/gregorian_types.cpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace boost; int main() { boost::timer t; boost::progress_display pd(100); for (int i = 0; i < 100; ++i) //progress bar { ++pd; } boost::gregorian::date dt(2009, 12, 8); //date_time library assert(dt.year() == 2009); assert(dt.day() == 8); boost::gregorian::date::ymd_type ymd = dt.year_month_day(); std::cout<<"\n"<<ymd.year<<"/"<<ymd.month<<"/"<<ymd.day<<" the day is " <<dt.day_of_year() <<" days of this year"<< std::endl; std::cout << boost::gregorian::to_iso_extended_string(dt) << std::endl; //Convert to other formats std::cout << boost::gregorian::to_iso_string(dt) << std::endl; std::cout << boost::gregorian::to_simple_string(dt) << std::endl<<std::endl; //Sort array operation std::vector<int> test_vc(100); std::vector<int>::iterator beg_it = test_vc.begin(); std::vector<int>::iterator end_it = test_vc.end(); std::srand(std::time(NULL)); std::for_each(beg_it, end_it, [](int& n){n = rand(); }); std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " ")); std::cout << std::endl << std::endl; std::sort(beg_it, end_it, std::greater<int>()); std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " ")); std::cout << std::endl<<std::endl; boost::posix_time::ptime pt(boost::gregorian::date(2005, 2, 6)); std::cout << t.elapsed() << "s" << std::endl; //Program run time system("pause"); return 0; }
Note: there is a small problem with the code in the original post. When compiling my vs version, the error is C2084 The function "const char *boost::date_time::nth_as_str(int)" already has a body , Error from date_generators.cpp file.
Solution: delete the following statement directly
#include <libs/date_time/src/gregorian/date_generators.cpp>
The guess is that the contents of this boost library have been added to the new C + + standard library, so the function definition in this file conflicts with the function definition in the original C + + standard library, so the program can run normally after being deleted directly.
The program runs correctly:
The above part is reproduced from: Basic usage of boost library under windows , It has been deleted.