I need to read data from a file into an array of structs. The info is arranged in the file like so...
Spear of Extreme Whaling
January
1851
Captain
Ahab

Each member of the array has a name, month, year, and first and last name of creator.
This is the beginning of my code:

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;

struct artifact
{
	string name;
	string month;
	int year;
	string fname;
	string lname;
};

int main()
{
	artifact allInfo[31];
	char menu;
	char yn;
	int j=0;
	string name;
	string filename;
	string yearTemp;
	ifstream inFile;
	ofstream outFile;
	cout<<"Enter a file name: "<<endl;
	cin>>filename;
	inFile.open(filename.c_str());
	while(!inFile.eof())
	{
		getline(inFile, allInfo[j].name);
		getline(inFile, allInfo[j].month);
		getline(inFile, yearTemp);
		getline(inFile, allInfo[j].fname);
		getline(inFile, allInfo[j].lname);
		allInfo[j].year=atoi(yearTemp.c_str());
		j++;
	}

I've checked to make sure that the file is opening.

And now what? What is your question?

Please don't say "it doesn't work".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.