Copying to binary file row of a matrix
Posted
by
Flethuseo
on Stack Overflow
See other posts from Stack Overflow
or by Flethuseo
Published on 2011-01-11T23:18:36Z
Indexed on
2011/01/11
23:53 UTC
Read the original article
Hit count: 231
c++
Hi everyone
I want to write each row of a matrix to a binary file. I try writing it like this:
vector< vector<uint32_t> > matrix;
...
for(size_t i = 0; i < matrix.size(); ++i)
ofile->write( reinterpret_cast<char*>(&matrix[i]), sizeof(uint32_t*sizeof(matrix[i])) );
{
for(size_t j = 0; j < numcols; ++j)
{
std::cout << left << setw(10) << matrix[i][j];
}
cout << endl;
}
but it doesn't work, I get garbage numbers.
Any help appreciated,
Ted.
© Stack Overflow or respective owner