Can anyone get this code to work?! im missing something or screwing up somewhere, but i cant get rid of a few errors. It can open the file but i don't know if the 2nd and 3rd functions are right.
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
struct Package{
float weight;
float length;
float width;
};
using namespace std;
bool openFile(ifstream &ins);
void inPack(ifstream &ins, Package &packList);
void getPkgs(ifstream &ins, Package *&packList, int &numPkg);
int main()
{
ifstream ins;
ofstream outs;
bool ok = openFile(ins);
if(ok){
Package *packList;
int numPkg;
getPkgs(ins, packList, numPkg);
}
}
bool openFile(ifstream &ins)
{
string str;
bool flag;
cout << endl;
cout << "Enter the name of the package data file: ";
cin >> str;
ins.open(str.c_str());
if (ins.fail())
{
cout << "Error opening file: " << str << endl;
exit (0);
}
ins.close();
return (!ins.fail());
}
void inPack(ifstream &ins, Package &packList)
{
ins >> packList.weight >> packList.length >> packList.width >> packList.depth;
return;
}
void getPkgs(ifstream &ins, Package *&packList, int &numPkg)
{
ins >> numPkg;
packList = new Package[numPkg];
for(int i = 0; i < numPkg; i++)
{
inPack(ins, &);
}
return;
}