If you are required to use the STL bitset class (as your code implies) then this should work a bit better (pun most definitely intended ):
Code:
#include <iostream>
#include <string>
#include <bitset>
int main()
{
std::bitset<8> bt;
bt.set(0);
std::cout<< bt.to_string() <<std::endl;
return 0;
}
If you have to create your own bitset class (a bit silly if you ask me), then consider using std::vector<bool>
Code:
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::vector<bool> bit;
bit.resize ( 8 );
bit[7] = 1; // Set the least signifigant bit
std::copy ( bit.begin(), bit.end(), std:: ostream_iterator<bool> ( std::cout ) );
std::cout<<std::endl;
return 0;
}
-Prelude