Working on a project where I need to read from a txt file where every three lines has us state information needed, where I have to parse the info into my class I created. I Know I need a couple for loops, but not sure how to format the code.
This is the format if the txt file:
New Hampshire
Concord
9304 1788 9
Massachusetts
Boston
8257 1788 6
Vermont
Montpelier
9609 1791 14
Every third line includes three seperate ints needed to be parsed. Here's my code so far:
int main()
{
ifstream file("Example_State_data.txt");
string name;
string capital;
int area = NULL;
int index = NULL;
int addYear = NULL;
int addOrder = NULL;
hashFunc States;
States.setStateInfo("Hawaii", "Honlulu", 0, 0, 0);
States.printTable();
if (file.is_open())
{
while (!file.eof())
{
file >> name;
index++;
}
cout << index << " items found";
file.close();
}
else
{
cout << "file is not open!";
}
}
void hashFunc::setStateInfo(string name, string capital, int area, int
admissionYear, int admissionOrder)
{
int index = Hash(name);
if (hashTable[index]->name == "empty")
{
hashTable[index]->name = name;
hashTable[index]->capital = capital;
hashTable[index]->area = area;
hashTable[index]->admissionYear = admissionYear;
hashTable[index]->admissionOrder = admissionOrder;
}