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

  • Home
  • SEARCH
  • 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 532863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:26:57+00:00 2026-05-13T09:26:57+00:00

I am trying to write a triple vector to a file and then be

  • 0

I am trying to write a triple vector to a file and then be able to read back into the data structure afterward. When I try to read the file back after its been saved the first fifty values come out correct but the rest of the values are garbage. I’d be really appreciative if someone could help me out here. Thanks a lot!

File declaration:

    fstream memory_file("C:\\Users\\Amichai\\Pictures\\output.txt", ios::in | ios::out);    

Save function:

void save_training_data(fstream &memory_file, vector<vector<vector<long double> > > &training_data)
 {
   int sizeI = training_data.size();
   memory_file.write((const char *)&sizeI, sizeof(int));
   for (int i=0; i < sizeI; i++)
   {
       int sizeJ = training_data[i].size();
       memory_file.write((const char *)&sizeJ, sizeof(int));
       for (int j=0; j < sizeJ; j++) 
       {
           int sizeK = training_data[i][j].size();
           memory_file.write((const char *)&sizeK, sizeof(int));
           for (int k = 0; k < sizeK; k++)
           {
               int temp;
               temp = (int)training_data[i][j][k];
               memory_file.write((const char *)&temp, sizeof(int));
           }
       }
   } 
 }

Read function:

void upload_memory(fstream &memory_file, vector<vector<vector<long double> > > &training_data)
{
     memory_file.seekg(ios::beg);
     int temp=0;
     int sizeK, sizeJ, sizeI; 
     memory_file.read((char*)&sizeI, sizeof(int));
     training_data.resize(sizeI);
     for (int i=0; i < sizeI; i++)
     {
           memory_file.read((char*)&sizeJ, sizeof(int));
           training_data[i].resize(sizeJ);           
           for (int j=0; j < sizeJ; j++)
           {
               memory_file.read((char*)&sizeK, sizeof(int));
               training_data[i][j].resize(sizeK);
               for (int k = 0; k < sizeK; k++)
               {
                    memory_file.read((char*)&temp, sizeof(int));
                    training_data[i][j][k]=temp;
               }
           }
     } 
}
  • 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-13T09:26:57+00:00Added an answer on May 13, 2026 at 9:26 am

    Since you’re writing binary data (and apparently working under Windows) you really need to specify ios::binary when you open the fstream.

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

Sidebar

Related Questions

I'm trying write a java program to send live microphone data over UDP, then
I m trying write code that after reset set up rrpmax as 3000. It
I am trying write a function that generates simulated data but if the simulated
Trying to write a couple of functions that will encrypt or decrypt a file
Trying to write a javascript bookmarklet to jump from a front end link into
Trying to write a simple C# script to copy file to directory one level
Trying to write a byte[] to a file, which i think is working correctly
I've been trying write an application which will be able to connect to a
I´m trying write strings in diffrent languages to a rtf file. I hav tried
I am trying write a script where when a user clicks on a link,

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.