Question: I'm trying read data from a file and store in a vector of structs. The code compiles and runs but i can't figure out why
I'm trying read data from a file and store in a vector of structs. The code compiles and runs but i can't figure out why nothing is printing
#include
struct stateAndBirths { string state; int births;
stateAndBirths(string n, int m) : state(move(n)), births(m) {} };
vector
string state; int births;
while (iss >> state >> births) { result.emplace_back(state, births); } for (auto &e : result) { cout << e.births << " " << e.state << endl; }
return result; }
int main() { ifstream inFile("student5_dataFile.txt"); auto students = read_data(inFile);
for (auto e : students) { cout << e.state << " " << e.births << endl; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
