Taking data from a text file and putting it into arrays.

Hi I need to take data from a text file "cost.txt" and be able to do some simple calculations like figure out the total cost, grand total etc, but the data in the file is formmated like this.
Books 45.01
Pens 21.03
Pencils 10.90
Hats 50.00
Caps 800.00
Food 1.00
Ideally i'd like to be able to pull out the items and store them in a string array and then also pull out the numbers and store them in a float array but I've had no luck in doing so. I can only seem to pull them all out then I have the issue of them all being a string when i need the cost to be float.

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
  //CALCULATE SALES ITEMS FROM FILE

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main ()
{
float totalPrice;
float totalSalesTax;
float grandTotal;
	string itemArray[999];


	ifstream inFile;
	inFile.open("cost.txt", ios::in);

//Check For Error
if (inFile.fail()){
	cerr <<"Error Opening File"<<endl;
	abort;
}

if(inFile.is_open())
{

for(int i=0; i<12; i++)
{
	inFile >> itemArray[i];
		
}
}
for (int ct = 0; ct < 12; ct++)
cout << itemArray[ct] << endl;
 return 0;
}
Topic archived. No new replies allowed.