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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:56:47+00:00 2026-06-06T21:56:47+00:00

void createVideoList(ifstream& ifile, Video videoArray[]) { string title; string star1; string star2; string producer;

  • 0
void createVideoList(ifstream& ifile, Video videoArray[])
{
string title;
string star1;
string star2;
string producer;
string director;
string productionCo;
int inStock;
int count = 0;
Video newVideo;
getline(ifile, title);
while (ifile)
{
    ifile >> inStock;
    getline(ifile, title);
    getline(ifile, star1);
    getline(ifile, star2);
    getline(ifile, producer);
    getline(ifile, director);
    getline(ifile, productionCo);
    videoArray[count] = Video(inStock, title, star1, star2, producer, director, productionCo);
    count++;
}
}

This is my code for a programming assignment. It will read in from a .txt file and is going to place the information into an array of a class I created.

The .txt is formatted like so:

3 (amount in stock)
Movie Title
Movie Star1
Movie Star2
Movie Producer
Movie Director
Movie ProductionCo

However, my code does not seem to be gathering the data correctly into the videoArray.
I just switched over from Java so my C++ syntax is a little rusty. Am I using getline correctly?
If I try to output one of the indexes, it has nothing in any of the variables. Thanks in advance!

  • 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-06T21:56:50+00:00Added an answer on June 6, 2026 at 9:56 pm
    Video newVideo;
    getline(ifile, title);
    while (ifile)
    {
        ifile >> inStock;
        getline(ifile, title);
        getline(ifile, star1);
        ...
    

    It is mostly correct, but there are a few problems:

    • The first getline, the one outside of the loop, shouldn’t be there. What is it supposed to read?
    • The loop test isn’t exactly correct — what happens if the last record is only partially present?
    • You have to be careful when you mix >> with getline. The >> doesn’t read in the remainder of the first line — specifically, it leaves the \n in the input stream. Use std::getline or istream::ignore to remove the pending end-of-line.
    • You are better of using a std::vector instead of an array, if the homework assignment allows it.

    Try:

    while (ifile >> inStock && getline(ifile, temporary_string) &&
           getline(ifile, title) &&
           getline(ifile, star1) &&
           ...
           getline(ifile, productionCo) )
    {
      videoVector.push_back(Video(inStock, title, ..., productionCo_));
    
      // Or, as a less worthy alternative, 
      //  videoArray[count] = Video(inStock, title, star1, star2, producer, director, productionCo);
      //  count++;
    }
    

    As a demonstration of the language features that you will learn in the coming weeks, here is one implementation of your program using modern C++ features:

    std::istream&
    operator>>(std::istream& is, Video& v)
    {
      is >> v.inStock;
      is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
      std::getline(is, v.title);
      std::getline(is, v.star1);
      std::getline(is, v.star2);
      std::getline(is, v.producer);
      std::getline(is, v.director);
      std::getline(is, v.productionCo);
      return is;
    }
    std::vector<Video> void createVideoList(std::istream& ifile)
    {
      std::vector<Video> result;
      std::istream_iterator<Video> begin(ifile), end;
      std::copy(begin, end, std::back_inserter(result));
      return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void getThisAlert(String Title, Displayable txtagency2) { Alert error = new Alert(, Title, null, AlertType.INFO);
void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I
- (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@respond to selector %d, [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQueue]
void foo(Node* p[], int size){ _uint64 arr_of_values[_MAX_THREADS]; for (int i=0 ; i < size
void AFCQueue::ExtractValuesSecComplex(int startIndex, int endIndex,int helperIndex) { int size = 0,i,index; TimeType min_timestamp; bool
void f(int){} typedef void (*f_ptr)(int); struct Functor{ void operator()(int){} }; struct X{ operator f_ptr(){
void child(int pid){ printf(Child PID:%d\n,pid); exit(0); } void parent(int pid){ printf(Parent PID:%d\n,pid); exit(0); }
void foo(int) { } class X { void foo() { } void bar() {
- (void) doSomething: (id)with { int a; a = [with doSomething]; } How does
void sort(int a[], int b[], int m, int n) { int e = m

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.