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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:40:49+00:00 2026-06-16T00:40:49+00:00

I have this iStream function to read in a .txt file of data in

  • 0

I have this iStream function to read in a .txt file of data in the format of:

  Pink Floyd: Dark Side of the Moon
  0:01:30 - Speak to Me

My function almost works perfectly.

Here are my problems that I just can’t figure out.
1) It prints (outputs) as each track is added to an Album (so prints x copies of the first album, each with the next track attached.
2) When a new Album is created, it keeps the old tracks from the previous album and continues to add them one-by-one. (so the final album has every single track from all albums)

Obviously I want each album to only be printed once, and each album to only have its own songs… Any help would be appreciated. Thanks.

  • 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-16T00:40:50+00:00Added an answer on June 16, 2026 at 12:40 am

    I see a number of problems with your code.

    stringstream stringstreamFirst(line);

    You aren’t using the variable stringstreamFirst and line is empty at this point.

    Album anAlbum(artistName,albumTitle,trackVector);

    There are a number of problems with this line.

    • It’s using the wrong values.
      One the very first line, artistName, albumTitle, and TrackVector are empty. When you finally come across a new album, the artistName, albumTitle, and TrackVector are those for the previous album, not the current one. The values are correct by the time you get to the tracks on an album — but that’s not when you want to create a new album object.
    • It’s in the wrong place.
      As placed, this statement creates an Album object for each line in the input file. The right place to create a new album object is when you have encountered a new album entry in the input file.

    stringstream stringstreamNew(line);
    stringstream stringstreamNewNew(line);

    Why the convoluted names, and why do you need two variables? An alternative would be to use but one stringstream, created as the first line of your while loop.

    if (!(line[8] == ‘-‘))
    else if (line[8] == ‘-‘)

    Don’t replicate your boolean conditions like this. If you mean else (which is what you mean), just use else. The line is either an album entry or a track entry; there is nothing else.

    else // These lines are missing

    You don’t have any error handling. What if you can’t parse what presumably should be an album entry, or what presumably should be a track entry?

    What you need to do (pseudocode):

    while (getline(istr, line)) {
       stringstream linestream (line);
       if (line looks like an album line) {
          if (not the first line in the file) {
              // Create an album using the artist name, album title, and track vector
              // and add this album onto the vector of albums
          }
          // Parse the line for artist name and album title, preferably handling errors
          // Clear the trackVector that now pertains to the previous album
       }
       else {
          // Parse the line for track duration and name, preferably handling errors
          // Add the track to the track vector.
       }
    }
    // Create an album to cover the last album plus set of tracks
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a function that read config file and i wanted to reload this
I've a very simple function that should read a txt file and return all
I have a sample txt file and want to read the contents of the
I'm writing a program for an exercise that will read data from a file
In my program, I've redirected stdout to print to a file 'console.txt'. A function
I am implementing a template function to read a file and file-like entities into
This program is supposed to open a txt file, record the answers from two
For this program i have only used field separators from data files in shell
I have this code. From main function i twice call sportPrisevinners function and if
I was working on this function read. The main I used has no problem

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.