Dec 3, 2012 at 5:22am UTC
For now all I'm trying to do is read from the file into a array of structs but it's not working. I have it open 4 times because I thought that would help. Without trying to read into anything but movie[i].name, the program reads all the names of the movies. but when I try to get all the info the compiler complains. I don't understand whats wrong.
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
using namespace std;
struct movie
{
string name;
int releaseYear;
string director;
int vote;
};
int main()
{
const int size=32;
movie movies[size];
ifstream moviefile;
moviefile.open("movies.txt");
int i=0;
string skip;
for (i=0; i<size; i++)
{
getline(moviefile,movies[i].name);
getline(moviefile,skip);
getline(moviefile,skip);
getline(moviefile,skip);
}
moviefile.close();
moviefile.open("movies.txt");
for (i=0; i<size; i++)
{
getline(moviefile,skip);
getline(moviefile,movies[i].releaseYear);
getline(moviefile,skip);
getline(moviefile,skip);
}
moviefile.close();
moviefile.open("movies.txt");
for (i=0; i<size; i++)
{
getline(moviefile,skip);
getline(moviefile,skip);
getline(moviefile,movies[i].director);
getline(moviefile,skip);
}
moviefile.close();
moviefile.open("movies.txt");
for (i=0; i<size; i++)
{
getline(moviefile,skip);
getline(moviefile,skip);
getline(moviefile,skip);
getline(moviefile,movies[i].vote);
}
moviefile.close();
for (i=0;i<size; i++)
{
cout<<movies[i].name<<" ";
movies[i].releaseYear<< " "
<<movies[i].director<<" "
<< movies[i].vote <<endl;
}
}
Dec 3, 2012 at 8:26am UTC
what coder777 said and i think you want to remove the ";" in the first line of your last for loop