Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

}

Explanation / Answer

hi this is you program here i have done it you have to include all abouve mentioned header files// starts from here using namespace std; struct SRTest { unsigned int comb; unsigned int src; }; int srcInversions = 0; ector populate(string combRankFile) //It opens file but nothing copies so let me check { vector sList; ifstream file("input.txt"); int number; SRTest site; if (file.is_open()) { do { file.read((char*)&site,sizeof(SRTest));//Read an object from file sList.push_back(site);//Push it into the vector } while (!file.eof()); } else cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote