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 #include #include #include #include using namespace std;

struct stateAndBirths { string state; int births;

stateAndBirths(string n, int m) : state(move(n)), births(m) {} };

vector read_data(istream& iss) { vector result;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!