本文整理汇总了C++中BitArray::to_string方法的典型用法代码示例。如果您正苦于以下问题:C++ BitArray::to_string方法的具体用法?C++ BitArray::to_string怎么用?C++ BitArray::to_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitArray
的用法示例。
在下文中一共展示了BitArray::to_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// Test program
int main() {
// Test exceptions
BitArray<> b;
throw_(b[0],logic_error);
throw_(b.toggle(0),logic_error);
const BitArray<> b1{b}; // Test copy constructor
throw_(b1[0],logic_error);
// Test empty Bitarray properties
test_(b.size() == 0);
test_(b.count() == 0);
test_(b.capacity() == 0);
test_(!b.any());
// Validate construction and to_string()
BitArray<> b2{5};
test_(b2.size() == 5);
for (size_t i = 0; i < 5; ++i) {
test_(!b2[i]);
}
test_(b2.to_string() == "00000");
// Test copy, assign, equality, and from_string
BitArray<> b3{b2};
test_(b2 == b3);
test_(b != b2);
test_(!b3[2]);
b3[2] = 1;
test_(b3[2]);
test_(b2 != b3);
test_(b2.to_string() == "00000");
b = b2;
test_(b.to_string() == "00000");
// Test move operations
BitArray<> b4{move(b3)};
test_(b4[2]);
BitArray<> b4b;
b4b = move(b4);
test_(b4b[2]);
// Test bit ops
BitArray<> x{"011010110"}; // Also tests string constructor
test_(x.count() == 5);
test_(x.any());
test_((x << 6).to_string() == "110000000");
test_((x >> 6).to_string() == "000000011");
test_((x <<= 3).to_string() == "010110000");
test_((x >>= 3).to_string() == "000010110");
BitArray<> y{~x};
nothrow_(x.toggle());
test_(x == y);
test_(x.to_string() == "111101001");
b = BitArray<> {};
test_(!b.any());
b += 1;
b += 0;
b += 1;
test_(b.to_string() == "101");
test_(b.any());
b2 = BitArray<> {"10101011"};
test_(b2.count() == 5);
b2.toggle();
test_(b2.to_string() == "01010100");
b2.erase(3);
test_(b2.to_string() == "0100100");
b2.erase(b2.size() - 1);
test_(b2.to_string() == "010010");
b2.erase(1,4);
test_(b2.to_string() == "00");
b2.insert(1,1);
test_(b2.to_string() == "010");
b2.insert(1,0);
test_(b2.to_string() == "0010");
b2 += b;
test_(b2.to_string() == "0010101");
b2.insert(3, b);
test_(b2.to_string() == "0011010101");
ostringstream os;
os << "101" << 'a' << "0101";
istringstream is{os.str()};
b3 = BitArray<> {};
is >> b3;
test_(b3.to_string() == "101");
is.get();
is >> b3;
test_(b3.to_string() == "0101");
os.str("");
os << 'a';
istringstream is2{os.str()};
is2 >> b3;
test_(!is2);
test_(b3.to_string() == "0101");
BitArray<> b5{"11111111111111111111111111000000000000000000000000000011"};
test_(b5.slice(23,10) == BitArray<>("1110000000"));
//.........这里部分代码省略.........