I convert a character to binary using std::bitset<CHAR_BIT> binary('c');
but this doesn’t work for a string,
std::string str = "MyString";
std::bitset<SIZE_OF_STRING_IN_BITS> binary(str); //Error Exception
what should be the alternative?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could repeat this action over every character of the string, shifting the bitset by CHAR_BIT to the left every time:
Seeing as the size of the bitset has to be a constant expression, I would go with
boost::dynamic_bitsetunless this string is a compile-time constant.