1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main()
{ ifstream file;
string a[10]; // What's this for?
string z,pop1950,pop1970,pop1990,pop2010,pop2015,name;
file.open("population.csv");
if (!file.is_open())
{ cout <<"Error opening file" << endl;
return 1;
}
while (getline(file, z))
{ stringstream ss (z);
getline (ss, pop1950, ',');
getline (ss, pop1970, ',');
getline (ss, pop1990, ',');
getline (ss, pop2010, ',');
getline (ss, pop2015, '\n');
// getline(file, name); // Commented this out as not sure the format of your file
cout << pop1950 << " " << pop2015 << endl;
}
return 0;
}
|