I'm trying to sort and populate a vector of objects with integers from a file. int fileSize reads the first line to determine how many numbers I should read after that. I'm kind of having trouble understanding pointers so could somebody at least help me get this working?
I got it to work when my vector type is <int> but i can't seem to populate a vector with a class IPRecord as the object.
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include "IPRecord.hpp"
using namespace std;
int main()
{
vector<IPRecord*> v;
ifstream inputFile("input.txt");
int fileSize;
inputFile >> fileSize;
//populate vector and sort
for (int i = 0; i < fileSize; i++)
{
int val;
inputFile >> val;
v.insert(lower_bound(v.begin(), v.end(), val), val);
}
//print
for (int i = 0; i < v.size(); i++)
{
cout << v[i] << endl;
}
inputFile.close();
return 0;
}