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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:47:03+00:00 2026-06-13T08:47:03+00:00

I am trying to write a mock bookstore program. The program is to read

  • 0

I am trying to write a mock bookstore program. The program is to read data from one input file and write it to one output file. I have several constraints. I can only use one input file, and one output file. I must use two for loops. One for each of the five customers listed in the file, and another for each of the books they are going to buy, with a possibility of up to 5 books.

The first for loop takes input for customer information, and the number of books to be bought(so next for loop will know how many times to iterate). Second loop takes information about the books.

Problem: I know how to keep an output file from writing over itself, but how do I get the input file to read from where the last iteration of the loop left off.

For some reason when I try to post my code it is reformatting it, and adding characters that shouldn’t be there. But here is psuedo-code for what I am trying to do.

for(count=1; count<=5; count++)
   {
   fin.open("input.txt");
   fin << user information(including name, address and number of books)
   fout.open("output.txt" ios::app);
   fout >> user information

   for(count1=1; count1<=numbbooks; count1++)
      {
      fin << book information(Name, Author, Price)
      fout >> book information
      }

I know how to use getline, fin, to take in the data, however after the first iteration of each loop it begins to read from the beginning of the file. I need it to read from where the previous iteration finished. I understand ios:app for the output.

sample input file

user name
address
number of books
book1
price1
book2
user name2
address
number of books
book2.1
price2.1

etc. There is actually more information than that. Any help would be greatly appreciated. Sorry for the newb question. I searched and searched before posting here.

  • 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-13T08:47:04+00:00Added an answer on June 13, 2026 at 8:47 am

    Simple don’t open and close it each time round the loop. Open it once before the outer loop, and close once after the same loop.

    When you open a file the read/write position is normally set to the start of the file (ios::app is an exception as you’ve already found out).

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

Sidebar

Related Questions

I am trying to use session to pass some data from one page to
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
I'm trying to write a test can I mock a HttpRequestBase to return post
For unit testing purposes I'm trying to write a mock object of a class
I'm trying to write a test for a method where the output depends on
I'm trying ot write an integration test for one of my methods, that handles
I am trying to write my first unit test for one of my service
I have an HttpServlet that I'm trying to write tests for and have mocked

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.