Movie Data and Structures

I'm getting some error saying I need an initializer before the " . " , what do I do?

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* 

#include<iostream>
#include<cstring>
#include<stdlib.h>

#define NUM_MOVIES 5

using namespace std;

struct movie_record{
   string title[NUM_MOVIES];
   int year[NUM_MOVIES];
   string rating[NUM_MOVIES];
   string description[NUM_MOVIES];
   string genre[NUM_MOVIES];
};

int set_movie(){
   movie_record movies[NUM_MOVIES];

  const char* movies[0].title="titleone" ;
  const char* movies[0].year="yearone"; 
  const char* movies[0].rating="G";
  const char* movies[0].description="descriptionone";
  const char* movies[0].genre="Fantasy";

   const char* movies[1].title="titletwo";
   const char* movies[1].year="yeartwo";
   const char* movies[1].rating="G";
   const char* movies[1].description="descriptiontwo";
   const char* movies[1].genre="Fantasy";

   const char* movies[2].title="titlethree";
   const char* movies[2].year="yearthree";
   const char* movies[2].rating="G";
   const char* movies[2].description="descriptionthree";
   const char* movies[2].genre="Adventure";

   etc....
}

int main(){
   cout<<"View all movies?(y/n) ";
   char view;
   cin>>view;
   
    
   movie_record movies[NUM_MOVIES];

   if ( view == 'y' || view == 'Y'){
      for (int i; i<NUM_MOVIES; i++){
	 cout<< movies[i].title<< ", "<< movies[i].year<<", "<<
	    movies[i].rating<<", "<< movies[i].description<<", "<<
	    movies[i].genre<<endl;
      }
   }
   else if (view == 'n' || view == 'N'){
   }
} */
aha! I saw this code the other day, from another user. I helped him/her!!

Anyway, you need to remove the const char * from lines 22 - 38 etc...
Drop all those const char* in front of movies. No idea why you think you need those. Then you declared "year" as an int, and then assign a string to it, which also makes no sense.
Haha. When I dropped const char* I get an error!
movies.cpp:56: error: incompatible types in assignment of âconst char [10]â to âstd::string [5]â
Yeah, drop the part in the brackets in your struct declaration too.


No wait. Rather than that, get yourself a C++ book. A good one. Stroustroup's supposedly good:

http://www.stroustrup.com/Programming/
Topic archived. No new replies allowed.