Alternative if you are using C ++ 11:
#include <iostream>
#include <string>
#include <sstream>
#include <bitset>
int main()
{
std::string data = "01110100011001010111001101110100";
std::stringstream sstream(data);
std::string output;
while(sstream.good())
{
std::bitset<8> bits;
sstream >> bits;
char c = char(bits.to_ulong());
output += c;
}
std::cout << output;
return 0;
}
Note that the bitset is part of C ++ 11.
Also note that if the data is not generated correctly, the result will be truncated when sstream.good () returns false.
source
share