Read from file to an array of pointers
Mar 28, 2015 at 3:10pm UTC
I have an assignment where I have to read a file into an array of pointers for a "Parts" object. I'm stuck. I think I get the logic of it, but I need help thinking it out. Here's what I have so far...
Part.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//Declare Part Class
class Part
{
private :
string Name;
int ID;
int Quantity = 0;
double Price = 0;
public :
Part(string, int , int , double );
};
int _tmain(int argc, _TCHAR* argv[])
{
string name;
int id;
int qty;
double price;
short i;
Part * parts[100];
ifstream xx;
xx.open("Inventory.dat" );
xx >> name;
while (!xx.eof())
{
getline(xx, name);
}
return 0;
}
Inventory.dat
1 2 3 4
Hammer 100 10 5.95
Nails 101 100 0.10
ScrewDriver 102 25 2.95
Last edited on Mar 28, 2015 at 3:11pm UTC
Topic archived. No new replies allowed.