Hello everyone.
I am attempting to read data from a file but am having some troubles.
My data file is labeled LAB5.DAT
and its info is the following, exactly:
10A111AX145
STEEL HAMMER
10.95
My goal here is to read in the first two letters/numbers, then the next one by itself, then the following 8.
IE:
Part number- 10
Division - A
Bin # - 111AX145
Then read in the description, then the price.
I have successfully written the program to read in the first line of data into the correct variables but cannot figure out how to read in the dscription or price, because they are on seperate lines. Here is my program so far...
Code:
int main()
{
ifstream LAB5;
LAB5.open ("LAB5.DAT");
int department;
char part_number[9];
char bin;
char description[14];
float unit_price;
LAB5 >> setw(3) >> department;
LAB5 >> setw(2) >> bin;
LAB5 >> setw(9) >> part_number;
LAB5.ignore(200);
LAB5.getline(description, 14);
LAB5 >> setw(5) >> unit_price;
cout << "department = " << department << endl;
cout << "bin = " << bin << endl;
cout << "part_number = " << part_number << endl;
cout << "description = " << description << endl;
cout << "unit price = $" << unit_price << endl;
LAB5.close();
return 0;
}
When I compile and execute the program, this is how it reads:
department = 10
bin = A
part_number = 111AX145
description =
unit price = $0
*Please help. Not sure what im doing wrong!*
-Mike