문제

내 비트 스트림을 문자열로 캡처하고 문자열을 계속 연결해야합니다. 그러나 어떻게 해야할지 잘 모르겠습니다. 어떤 아이디어?

#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;
}

'// 자리 표시 자'가 표시된 줄에서, 나는 그것을 'cout'할 필요가 없으며, 오히려 비트 스트림을 문자열에 캡처하고 계속 연결해야합니다.

도움이 되었습니까?

해결책

std :: stringstream?

#include <sstream>

std::string WriteSomethingToStringStream()
{
    std::ostringstream oss;
    oss << "foo?\n";
    oss << "bar!\n";
    return oss.str();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top