Essentially after running all of the below code, I'm aiming to output a single element of my Countries vector just to test and see if I'm actually populating it or not. Nothing is outputting though, no errors are met and If I screwed something up I have no clue how to go about fixing it.
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <vector>
using namespace std;
struct Country {
string Name;
string Population;
string Area;
string Density;
string Migration;
string GDP;
string Literacy;
string Birthrate;
};
int main(){
ifstream data ("countries.csv");
vector<Country> Countries;
while (data.good()){
Country temp;
getline(data, temp.Name, ',');
getline(data, temp.Population, ',');
getline(data, temp.Area, ',');
getline(data, temp.Density, ',');
getline(data, temp.Migration, ',');
getline(data, temp.GDP, ',');
getline(data, temp.Literacy, ',');
getline(data, temp.Birthrate, '\n');
Countries.push_back(temp);
}
Country c1 = Countries[1];
Country c2 = Countries[2];
cout << c1.Name << ", " << c1.Population << ", " << c1.Area << ", "
<< c1.Density << ", " << c1.Migration << ", " << c1.GDP << ", "
<< c1.Literacy << ", " << c1.Birthrate << endl;
cout << c2.Name << ", " << c2.Population << ", " << c2.Area << ", "
<< c2.Density << ", " << c2.Migration << ", " << c2.GDP << ", "
<< c2.Literacy << ", " << c2.Birthrate << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire