-
Bitset 의 예C++ 2014. 2. 22. 07:38
void main()
{
bitset<10> myBitset; // 10 bits의 객체 생성
myBitset.set(3); // set 3th bit
myBitset[4]=true; // set 4th bit
myBitset[9]=myBitset[3]; // copy from 3th bit
bitset<10> secondBitset(myBitset); // copy constructor
// bitset<10> thirthBitset= myBitset; // copy constructor
bitset<10> thirthBitset= ('0','1','0','1','0','1','0','1','0','1','0','1'); // copy constructor constructor
auto str1 = "010101010101";
bitset<10> fourthBitset(str1); // copy constructor
auto str2 = "101010101010";
bitset<10> fifthBitset(str2);
bitset<10> sixthBitset(fourthBitset|fifthBitset);
for (int i=0;i<10;++i) {
cout << "myBitset["<<i<<"]= "<< myBitset[i] << endl;
cout << "secondBitset["<<i<<"]= "<< secondBitset[i] << endl;
cout << "thirthBitset["<<i<<"]= "<< thirthBitset[i] << endl;
cout << "fourthBitset["<<i<<"]= "<< fourthBitset[i] << endl;
cout << "fifthBitset["<<i<<"]= "<< fifthBitset[i] << endl;
cout << "sixthBitset["<<i<<"]= "<< sixthBitset[i] << endl;
}
CableCompany myCable;
auto basic_package = "1111000000";
auto premium_package = "1111111111";
auto sport_package = "0000111000";
auto international_package = "0000000111";
myCable.addPackage(string("Basic"), bit10(basic_package));
myCable.addPackage(string("Primium"), bit10(premium_package));
myCable.addPackage(string("Sport"), bit10(sport_package));
myCable.addPackage(string("International"), bit10(international_package));
myCable.newCustomer(string("Mike"), bit10(basic_package));
myCable.newCustomer(string("Kathy"), bit10(premium_package));
myCable.newCustomer(string("Neal"), bit10(sport_package));
myCable.newCustomer(string("John"), bit10(international_package));
myCable.newCustomer(string("Ron"), bit10("11111000"));
myCable.newCustomer(string("Mary"), bit10("11111110"));
myCable.addPackageToCustomer(string("Mike"), string("Sport"));
myCable.print();
}
'C++' 카테고리의 다른 글
Character array literal (0) 2014.02.25 Algorithm (find , find_if) (0) 2014.02.22 MultiMap (0) 2014.02.22 STL map 의 정리 (0) 2014.02.20 Packet Queue Example Code (0) 2014.02.20