#include <iostream>
#include <istream>
#include <streambuf>
#include <string>
#include <sstream>
using namespace boost;
using namespace std;
int main() {
int val;
stringstream ss(stringstream::in | stringstream::out | stringstream::binary);
unsigned char buffer[20];
unsigned char in[5] = { 0xAA, 0xBB, 0x00, 0xDD, 0xEE };
ss << in;
ss >> buffer;
printf("%x %x %x %x %x",buffer[0],buffer[1],buffer[2],buffer[3],buffer[4]);
return 0;
}
그럼 출력은 당연히 aa bb 00 dd ee 인줄 알았는데 바이너리 모드라서
개뿔
aa bb 00 cc cc 뜸
널값에서 끊어버림
스트링스트림 대신 바이너리스트림으로 쓸만한 스트림 추천점
너가 원하는 게 메모리 스트림 개념인 거 같은데
http://stackoverflow.com/questions/1448467/initializing-a-c-stdistringstream-from-an-in-memory-buffer/1449527#1449527
를 참고해 봐
형님 사랑합니다