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 8477781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:33:38+00:00 2026-06-10T18:33:38+00:00

The read function has it’s first argument as pointer to an array to store

  • 0

The read function has it’s first argument as pointer to an array to store the n bytes(mentioned by the second argument) in the file…

The query is,

if i have created 2 objects of class x..

then,

x stack[2]; 

Assume i’ve filled the 2 object contents, opened a file ‘xyz'(using fstream i’ve created object file & used the command file.open("xyz",ios::in|ios::out) and filled the file with contents of 2 objects using write..

now if i use this command

file.read((char*) &stack[1],sizeof(stack[0]))

will the stack[1] have the contents of stack[0],

i.e. will the read function take it’s first argument address as &stack[1] or will it consider &stack[0] ??

Update:The code which is used to reverse the contents of the stack

//
//To reverse the contents of the objects

    #include "stdafx.h"
    #include<iostream>
    #include<fstream>
    #include<iomanip>

    using namespace std;

    class Inventory
    {
     char name[10];
     int code;
     int cost;

     public:

     void readdata();
     void writedata();
    };

    void Inventory::readdata(void)
    {
     cin>>name;
     cin>>code;
     cin>>cost;
    }

    void Inventory::writedata(void)
    {
     cout<<setiosflags(ios::left)
     <<setw(10)<<name
     <<resetiosflags(ios::right)
     <<setw(10)<<code
     <<setprecision(2)
     <<setw(10)<<cost
     <<endl;
    }

    int main()
    {
     Inventory item[3];

     fstream file;

     file.open("Stock",ios::in|ios::out);

     cout<<"Enter details for three items\n";

     for(int i=0;i<3;i++)
     {
       item[i].readdata();
       file.write((char*) &item[i],sizeof(item[i]));
     }
     file.seekg(0);

     cout<<"\nOutput\n\n";

     for(int i=0;i<3;i++)
     {
         file.read((char*) &item[2-i],sizeof(item[i]));
     }

     for(int i=0;i<3;i++)item[i].writedata();
     file.close();
     return 0;

    }
  • 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-06-10T18:33:39+00:00Added an answer on June 10, 2026 at 6:33 pm

    Try this:

    file.open("Stock",ios::in|ios::trunc|ios::out);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple file read and write function. private void WriteToFile(String filename, String
My map function has to read a file for every input. That file doesn't
I have to share serial port read function with two other functions, basically first
I just don't get it. I have a function to read stemmed strings from
I think I read something about a function appengine has that can tell whether
i want to read\write a binary file which has the following structure: The file
Let's say that any C function has a pointer already declared, but not assigned
I have a function that has event handler. It is reading gps position and
I have a code: class db { var $connection; function escape($esc) { return str_replace(array('%','_'),array('\%','\_'),mysqli_real_escape_string($this->connection,$esc));
I am using a library that has a function that takes an array of

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.