Pointers to structure with arrays
Apr 10, 2015 at 10:34pm UTC
Hi. I am trying to apply 'Pointers to structure' to 'arrays'
but I think I got some error. What I wanted to do was to make three input and output by using pointers. Could you let me know what are the erros?
I know it is messy but please.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
struct movies_t
{ string title;
int year;
};
movies_t films[3];
movies_t * pmovie[3];
void printmovie (movies_t &movie);
int main ()
{
string mystr;
int n;
pmovie[3]=&films[3];
for (n=0; n<3; n++)
{
cout << "Enter title: " ;
getline (cin,pmovie[n]->title);
cout << "Enter year: " ;
getline (cin,mystr);
stringstream (mystr) >> pmovie[n]->year;
}
cout << "You have entered : " << '\n' ;
for (n=0; n<3; n++)
{ printmovie(pmovie[n]);
}
}
void printmovie(movies_t &movie)
{
cout <<&movie->title ;
cout << "(" << &movie->year << ")" << '\n' ;
}
Apr 10, 2015 at 10:37pm UTC
Topic archived. No new replies allowed.