0

I'll need to capture my bitstream into a string and keep concatenating the string. However, I'm not really sure how it's to be done. Any ideas?

#include <bitset>
#include <iostream>
#include <string>

using namespace std;


int main ()
{

  int i;

  char data[30];
  int int_arr[30];

   printf("\nEnter the Data Bits to be transmitted : ");
 scanf("%s",data);

 // convert it into bitstream

 for (i=0; i<strlen(data); i++)
 {

  int_arr[i] = int(data[i]);
 }


 for (i=0; i<strlen(data); i++)
 {
  cout << int_arr[i]<<endl;
  cout << std::bitset<8>( int_arr[i] )<<endl; // Placeholder
 }


  return 0;
}

In the line where it's marked '//Placeholder', I really do not need to 'cout' it, rather, I'd have to capture the bitstream into a string and keep concatenating it.

1 Answer 1

1

std::stringstream?

#include <sstream>

std::string WriteSomethingToStringStream()
{
    std::ostringstream oss;
    oss << "foo?\n";
    oss << "bar!\n";
    return oss.str();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.