views:

64

answers:

1

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  A: 

std::stringstream?

#include <sstream>

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