bitset type error

Jan 10, 2009 at 7:19pm
I have an exiting project that I am trying to use to learn c++. The project was originally created in VS6.0 I am using VS8.0

Just trying to build project I get error from this line:
std::bitset<2100> MsgBits(TempBits.GetBuffer(0));

error C2664: 'std::bitset<_Bits>::bitset(unsigned long)' : cannot convert parameter 1 from 'char *' to 'unsigned long'
with
[
_Bits=2100
]

CString TempBits; (declaration of TempBits)

I can understand that the bitset can not accept a string pointer, but I do not know how this may have worked from previously in VS6.0?

I tried casting std::bitset<2100> MsgBits((unsigned long)TempBits.GetBuffer(0));
and it compiled and debugged, but result was not correct.

Any help with this would be appreciated! Maybe I do not have something in the compiler set to allow this to compile without error?

Last edited on Jan 10, 2009 at 7:21pm
Jan 12, 2009 at 2:20am
It's a bit difficult from your code snippet to see the context how it is used but as you have seen bitset doesn't take a char* in the constructor so the code is wrong. Even if it was compiled with unicode which maybe would reduce the error to a warning in VS6 it would be a POS code anyway. If the intention was that TempBits contains 2100 '0' | '1' then you need to redesign this, it should be fairly easy to do a function to fill the bitset from such a string.

Topic archived. No new replies allowed.