문제

Here is some sample code

std::stringstream ss;
boost::archive::binary_oarchive oa(ss);
oa << newMat;
int size = ss.tellp();
void* matBin = malloc(size);
memcpy(matBin,ss.str().c_str(), size);

Basically I am attempting to store some matrices a binary data into a database. This code should turn the matrix into binary data (don't worry about the details of the boost archive), and I am attempting to store the data into a buffer. However, I am not sure if ss.tellp() is the proper way to determine the size of binary data.

Can anyone confirm if this a proper way to determine the size of ss?

Thanks!

도움이 되었습니까?

해결책

Like this

int size = ss.str().size();

but I see no reason why tellp wouldn't work as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top