خرید بک لینک

Vote count: 0

I want to extract data from a file and store them into the myWorld but my for loop doesn't work, the program doesn't loop one time once it gets to the for loop. I'm not sure what the problem is. This is my code so far.

#include <iostream>
#include <fstream> 
#include <string>
#include <cstdlib>
using namespace std;

struct Country 
 {
  double pop1950;
  double pop1970;
  double pop1990;
  double pop2010;
  double pop2015;
  string name;
 };

const int MAXCOUNTRIES = 300;

struct World 
 {
  int     numCountries;
  Country countries[MAXCOUNTRIES];
 } myWorld;

void printPop ();

int main ()
{
 printPop();
 retu 0;
}

void printPop()
{
 ifstream inFile("population.csv");

 if (!inFile.fail())
 {
    cout << "File has opened successfully.";
 }

 if (inFile.fail())
 {
  cout << "File has failed to open.";
  exit(1);
 }

 for (int i = 0; i < MAXCOUNTRIES; i++)
 {
    inFile >> myWorld.countries[i].pop1950 >> myWorld.countries[i].pop1970 >> myWorld.countries[i].pop1990
           >> myWorld.countries[i].pop2010 >> myWorld.countries[i].pop2015;
    getline (cin, myWorld.countries[i].name);
    cout << "loop is ruing" << endl;
 }

  inFile.close();
}

asked 48 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 2 ارديبهشت 1395 ساعت: 5:16

صفحه بندی