pointers to structures : Struct « Data Type « C++






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, 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;
}
  
    
  








Related examples in the same category

1.Defines and uses a struct.Defines and uses a struct.
2.example about structures
3.array of structures
4.uses parts inventory to demonstrate structures
5.demonstrates nested structures
6.demonstrates passing structure by reference
7.demonstrates passing structure as argument