Thread: errors with bitset

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    46

    errors with bitset

    I'm stumped as to why this code won't compile:
    Code:
    #include <bitset>
    int main () {	
    	std::bitset<8> b;	
    	return 0;
    }
    I get a whole slew of errors from gcc (2.95.2)
    Code:
    \JFEAND~1\PROGS\bitset.cpp: In instantiation of `bitset<8,long unsigned int>':
    \JFEAND~1\PROGS\bitset.cpp:3:   instantiated from here
    \JFEAND~1\PROGS\bitset.cpp:3: `CHAR_BIT' was not declared in this scope
    \JFEAND~1\PROGS\bitset.cpp:3: `CHAR_BIT' was not declared in this scope
    \JFEAND~1\PROGS\bitset.cpp:3: template argument 1 is invalid
    ..\lib\gcc-lib\i386-mingw32\2.95.2\..\..\..\..\include\bitset:541: `CHAR_BIT' was not declared in this scope
    ..\lib\gcc-lib\i386-mingw32\2.95.2\..\..\..\..\include\bitset:541: `CHAR_BIT' was not declared in this scope
    ..\lib\gcc-lib\i386-mingw32\2.95.2\..\..\..\..\include\bitset:541: template argument 1 is invalid
    and so on...
    any ideas?

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Is it std:: for bitset? I don't think it is. Take out the std:: and it should work.

    EDIT: I was wrong. It works fine for me though. The above code.

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I threw it into Dev C++ 4.9.9.2 on Windows XP SP2 and it compiled fine.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    also compiled fine with gcc 4.1.0
    signature under construction

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    46
    hmm... perhaps my older version of gcc has some strange implementation of bitset

  6. #6
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Try this, it prob won't make any difference, but throw in a 'using namespace std;', and take away the 'std::', and see if that works.

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    46
    Nope, same errors.
    Also tried adding using std::bitset.
    I think it's just a problem with my version of gcc.

    I get a ton of errors about "template argument 1 is invalid" and "CHAR_BIT' was not declared in this scope"

  8. #8
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I'd say if you need to do this program to get dev of something which will allow the use of <bitset>.

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    well gcc 2.95 isn't really up2date, so the implementation of the stl probably uses some constructs that were not supported back then.
    signature under construction

  10. #10
    Registered User
    Join Date
    Feb 2005
    Posts
    46
    Hmm I suppose October 27, 1999 (release date) was quite a while ago. It's probably time to upgrade.

    The thing is that the build is integrated into a text editor called Jen's File Editor, and I don't know how to integrate the new compiler build.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > \JFEAND~1\PROGS\bitset.cpp:3: `CHAR_BIT' was not declared in this scope
    You could try
    #include <limits.h>
    before including bitset

    But your compiler sounds pretty old to me.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    Feb 2005
    Posts
    46
    The limits.h didn't work either.
    It's ok, I switched over to Dev C++ with a newer version of gcc, and it works now.
    It's a better IDE anyways.
    Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM