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.
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;
}
}