How to convert binary string into an ASCII string in C++

1 Answer

0 votes
#include <iostream>
#include <sstream>
#include <bitset>

int main()
{
    std::string s = "011000110010101100101011";
    std::stringstream sstream(s);
    std::string output;
    
    while(sstream.good()) {
        std::bitset<8> bits;
        sstream >> bits;
        char ch = char(bits.to_ulong());
        output += ch;
    }

    std::cout << output;

   return 0;
}


/*
run:

c++

*/

 



answered Aug 2, 2020 by avibootz

Related questions

1 answer 177 views
1 answer 202 views
1 answer 92 views
2 answers 173 views
1 answer 186 views
1 answer 122 views
...