Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3677116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:10:56+00:00 2026-05-19T03:10:56+00:00

I want to write each row of a matrix to a binary file. I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:10:57+00:00Added an answer on May 19, 2026 at 3:10 am

    In case interjay’s guidelines weren’t enough:

    vector< vector<uint32_t> > matrix;
    
    for(size_t i = 0; i < matrix.size(); ++i) 
      ofile.write( (char*)&matrix[i][0], sizeof(matrix[i][0])*matrix[i].size() );
    

    Out-of-context question: Why is ofile a pointer? (certainly don’t need to be in this example)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to fetch each row when I call the following function: CpuReporting.getgridusage(300) This
I want to write a business object layer in a way that makes each
I want to write tests for my app, though each time I look at
I'm writing a sparse matrix class in C++ in which every row and column
I have 3 check boxes in each row of 8 total rows. I want
I have sample data like this df <- data.frame(name = rep(letters[1:7], each = 24),
I want to select the entire first row of each record where a promo
All I want is for the first column of each row in my table
I want to create custom row for ListActivity, each row contains Title and List
I have a HashMap and want to synchronize each row/entry separately in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.