structure-object structure-object-pointer

// pointers to structures
#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, amovie.title);   //using object
  cout << "Enter year: ";
  getline (cin, mystr);
  (stringstream) mystr >> pmovie->year;

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

  return 0;
}

posted @ 2015-09-26 15:46  greencolor  阅读(187)  评论(0编辑  收藏  举报