Boost C++庫是一個非常強大且功能豐富的C++庫,其中包含了許多高性能的容器類
#include<boost/array.hpp>
int main() {
boost::array<int, 5> arr = {1, 2, 3, 4, 5};
for (int i = 0; i < arr.size(); ++i) {
std::cout<< arr[i] << " ";
}
return 0;
}
#include<boost/container/vector.hpp>
int main() {
boost::container::vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
for (int i = 0; i < vec.size(); ++i) {
std::cout<< vec[i] << " ";
}
return 0;
}
#include<boost/container/list.hpp>
int main() {
boost::container::list<int> lst;
lst.push_back(1);
lst.push_back(2);
lst.push_back(3);
for (auto it = lst.begin(); it != lst.end(); ++it) {
std::cout << *it << " ";
}
return 0;
}
#include<boost/container/map.hpp>
int main() {
boost::container::map<std::string, int> m;
m["apple"] = 1;
m["banana"] = 2;
m["orange"] = 3;
for (const auto& p : m) {
std::cout << p.first << ": " << p.second<< std::endl;
}
return 0;
}
#include<boost/container/set.hpp>
int main() {
boost::container::set<int> s;
s.insert(1);
s.insert(2);
s.insert(3);
for (const auto& x : s) {
std::cout << x << " ";
}
return 0;
}
這些只是Boost C++庫中容器類的一部分,還有其他許多容器類可供使用。在使用這些容器類時,請確保已經正確安裝并配置了Boost庫,并在代碼中包含相應的頭文件。