Bringing in a file as an array using functions??

Homework Question:
I'm trying to get a file to open up using a function, going into an array. Then having the possibility of searching for information within the array.

using visual studios 2015

The code builds fine according to visual studios. The .csv file is in with the rest of the program file like I was instructed to place it. The only thing I am getting is the file isn't opening. I have double checked the spelling of the file name and it's correct.


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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  int main()
	{
	//declaring variables
	int choice;

	//bringing in file information
	Airport flyboys[MAX]; //arrays for airport info
	bringDataIn(flyboys);
	system("pause");

	//starting program fun stuffs
	MainMenu(); //stating main menu
	choice = MainMenu();

	//switch for menu options
	switch (choice)
	{
	case 1: //city name
	{
		CitySearch();
		break;
	}
	case 2: //FAA code
	{
		CodeSearch();
		break;
	}
	case 3: //Exit program
	{
		ExitPro();
		break;
	}
	default:
	{
		cout << "Invalid entry." << endl;
		system("pause");
	} //end default

	} //end of switch

	return 0;
	}





			void bringDataIn(Airport flyboysIn[MAX]) //reads data into the file
		{
		int counter = 0;

		ifstream DataIn("Airports.csv"); //opening file

		
		if (DataIn.is_open())//checking to see if file can be opened
		{
			cout << "File Opened successfully!!!. Reading data from file into array" << endl;
	
			while (!DataIn.good() && counter < MAX) //so long as the file is good and opened, do this stuff
			{
		
			getline(DataIn, flyboysIn[counter].state, ',');
			getline(DataIn, flyboysIn[counter].city, ',');
			getline(DataIn, flyboysIn[counter].faa, ',');
			getline(DataIn, flyboysIn[counter].iata, ',');
			getline(DataIn, flyboysIn[counter].icao, ',');
			getline(DataIn, flyboysIn[counter].airport_name, ',');
			getline(DataIn, flyboysIn[counter].role, ',');
			getline(DataIn, flyboysIn[counter].enplanements);
			counter++;




		}
		}
		else //file could not be opened
		{
			cout << "File could not be opened." << endl;
		}
		}
A snippet of the airports.csv file, if this helps any.

State,City,FAA,IATA,ICAO,Airport,Role,Enplanements
ALABAMA,Birmingham,BHM,BHM,KBHM,Birmingham–Shuttlesworth International Airport,S,1335215
ALABAMA,Dothan,DHN,DHN,KDHN,Dothan Regional Airport,N,48423
ALABAMA,Huntsville,HSV,HSV,KHSV,Huntsville International Airport (Carl T. Jones Field),S,505541
ALABAMA,Mobile,MOB,MOB,KMOB,Mobile Regional Airport,N,287661
ALABAMA,Montgomery,MGM,MGM,KMGM,Montgomery Regional Airport (Dannelly Field),N,157958
Replace line 79 with perror("File error: "); and see what it prints.
Include <cstdio> as well.
Topic archived. No new replies allowed.