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