// pointers to structures

/* 
We will now go with another example that includes pointers, 
which will serve to introduce a new operator: the arrow operator (->):
*/

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct movies_t {
  string title;
  int    year;
};

int main ()
{
  string mystr;

  movies_t amovie;
  movies_t * pmovie;
  pmovie = &amovie;

  cout << "Enter title: ";
  getline (cin, pmovie->title);
  cout << "Enter year: ";
  getline (cin, mystr);
  (stringstream) mystr >> pmovie->year;

  cout << "\nYou have entered:\n";
  cout << pmovie->title;
  cout << " (" << pmovie->year << ")\n";

  return 0;
}

/*
The previous code includes an important introduction: the arrow operator (->). 
This is a dereference operator that is used exclusively with pointers to objects with members. 
This operator serves to access a member of an object to which we have a reference. 
In the example we used: "pmovie->title"
Which is for all purposes equivalent to: "(*pmovie).title"
 
Both expressions "pmovie->title" and "(*pmovie).title" are valid and both mean that 
we are evaluating the member title of the data structure pointed by a pointer called pmovie. 
It must be clearly differentiated from: "*pmovie.title"
which is equivalent to: "*(pmovie.title)"

*/
 
