61STL

it2025-07-12  4

61STL_vector

基本概念示例代码

基本概念

bitset中容量大小是固定的,而vector< bool >的大小是可以动态调整的

实例化vector< bool >

示例代码

#include <iostream> #include <vector> #include <bitset> using namespace std; int main() { bitset<4> a; cout << a << endl; bitset<5> b(string("10101")); cout << b << endl; //动态调整位数vector<bool> vector<bool> x(3); x[0] = true; x[1] = true; x[2] = false; x.push_back(true); //动态增加数据 for(size_t nIndex=0; nIndex < x.size(); ++nIndex) cout << x[nIndex]; cout << endl; x.flip(); //求反 for(size_t nIndex=0; nIndex < x.size(); ++nIndex) cout << x[nIndex]; cout << endl; return 0; }
最新回复(0)