I was on Cplusplus tonight, learning a bit about data structures (which I like). Well, I copied and pasted one example, ran it, learned a bit. Then I tried the same for the second. Here's the code for the second...

// array of structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

#define N_MOVIES 3

struct movies_t {
  string title;
  int year;
} films [N_MOVIES];

void printmovie (movies_t movie);

int main ()
  string mystr;
  int n;

  for (n=0; n<N_MOVIES; n++)
    cout << "Enter title: ";
    getline (cin,films[n].title);
    cout << "Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> films[n].year;

  cout << "\nYou have entered these movies:\n";
  for (n=0; n<N_MOVIES; n++)
    printmovie (films[n]);
  return 0;

void printmovie (movies_t movie)
  cout << movie.title;
  cout << " (" << movie.year << ")\n";

Well it compiles and runs, but gives me this output, with any imput.

Now thats the output for the original program its giving me. They're saved as two different files, and I've only got one open at a time, and have tried exiting and re-entering the program. Was wondering what the deal behind something like this is?

12 Years
Discussion Span
Last Post by WolfPack

Looks like you haven't added the second file to the project or have added both files to the project. Remove the first file, and then add the second file. At anycase it is not a bug in your program, but the way you have setup the project for execution.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.