I am trying to get a list of number put them into a vector to be sorted then pri
ID: 3550469 • Letter: I
Question
I am trying to get a list of number put them into a vector to be sorted
then printed out.
#include <fstream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include<iostream>
#include <iterator>
#include <algorithm>
using namespace std;
struct siteRank
{
unsigned int combined;
unsigned int source;
};
int sourceInversions = 0;
vector<siteRank> populate(string combinedRankFile) //Here is where I think it is not working. It opens file but nothing copies
{
vector<siteRank> siteList;
ifstream file("combinedRankFile.txt");
string buffer;
istringstream iss;
if (file.is_open()) {
int id = 0;
do {
siteList.push_back(*new siteRank);
getline(file,buffer);
iss.str(buffer);
siteList.at(id).combined = atoi(&buffer[0]);
id++;
} while (!file.eof());
}
else
cout << "Unable to open file";
file.close();
return siteList;
}
int main()
{
int pause;
vector<siteRank> siteList1;
siteList1 = populate("combinedRanks.txt");
for (int i=0; i < siteList1.size();i++){
cout << siteList1[i] << endl;
}
cin>>pause;
return 0;
}