You want to create a
vector[
^] (or some other container) of the struct. This way the struct can hold all the data, and only the data, of a single instance of a Computer.
See
vector::end()[
^] for an example of how to iterate through all the elements in the container
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
struct Computer {
string Model;
string Manu;
int Price;
};
typedef vector<Computer> ComputerList;
void getComputer(Computer&, ifstream&, ofstream&);
int main() {
ComputerList data;
ifstream iFile;
ofstream oFile;
iFile.open("CompSys.txt");
oFile.open("CompLog.txt");
getComputer(data, iFile, oFile);
iFile.close();
oFile.close();
return 0;
}
void getComputer(ComputerList& list, ifstream& iFile, ofstream& oFile) {
int Idx;
int counter =100;
while(iFile) {
for (Idx = 0; Idx < counter; Idx++) {
Computer data;
getline(iFile, data.Model, '\t');
getline(iFile, data.Manu, '\t');
iFile >> data.Price;
list.push_back(data); }
}
}
This is just my changes yo your code, I have not tested it to make sure it works.