Pregunta

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!

¿Fue útil?

Solución

Like this

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

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top