Thread: bitset class and operations???

  1. #1
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53

    bitset class and operations???

    #include<iostream.h>
    #include<bitset.h>

    int main()
    {
    bitset bt;

    bt.set(0);

    cout<<bt.to_string()<<endl;
    return 0;
    }


    I am using microsofts C++ and it doesn't reconize the bitset.h, if I remove it the the rest bombs out???

    Am i using it incorrectly?

    I will continue searching for other solutions. Thanks

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    Try the standard headers

    <iostream>
    <bitset>

    using namespace std;

    etc
    Joe

  3. #3
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53
    I was able to get it to work using namespace std and passing it the correct size value of the templete, the problem lies is that we are not allowed to use namespace std and want to use the class by itself and it is not allowing me too. If there is another class or function that has the same funtionallity, please let me know. If worse comes to worse I will write me a home grown version. Thanks.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    So you've been instructed to use a standard class, but aren't allowed to use the standard headers? Curious. Perhaps you've mis-interpreted the question/request/assignment, and are supposed to write your own version of bitset?

    If not, I'm sure there are plenty of bitset implementations around such as this one. Seems a pretty pointless excersise though.
    Joe

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    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
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need the code of few programs in c++.plzzzzz help...plzzz
    By NAVINKR20 in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2009, 09:13 AM
  2. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  3. Access to methods of another (external) class
    By praul in forum C++ Programming
    Replies: 12
    Last Post: 04-19-2006, 11:42 AM
  4. String Class Operations
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 04-06-2003, 02:29 PM
  5. String Class Operations
    By Aidman in forum C++ Programming
    Replies: 0
    Last Post: 04-05-2003, 05:28 PM