I have a file where I need to get the first column of text and return it as an array and the rest of the file into a separate array.
The text file looks like:
Takoma_store 2.70 2.70 71.30 3.60 14.70 17.40 23.90 71.30 51.20 31.20 2.70 96.20
Bethesda_store 12.70 6.80 8.90 6.80 17.80 24.60 7.90 8.90 18.30 6.80 6.80 72.90
Arlington_store 22.50 1.40 17.60 1.40 32.50 33.90 2.70 17.60 4.80 1.40 1.40 89.40
Nashville_store 2.60 9.40 56.70 2.10 3.60 13.00 6.80 56.70 23.40 6.80 9.40 71.50
Springfield_store 9.60 14.10 8.30 3.15 6.80 16.20 1.40 8.30 3.70 1.40 9.40 87.25
Baltimore_store 6.50 21.15 8.90 2.73 89.40 98.15 9.40 8.90 9.80 6.80 8.75 110.88
Aurora_store 9.40 31.73 8.20 2.09 71.50 80.66 9.40 8.20 67.80 1.40 9.16 146.31
Everywhere there is a store name is a new line.
This is my code so far... it gets the first column and of store names and stores it into an array but the rest of the file needs to be placed inside of an array with 7 rows and 12 columns, can someone guide me on where to go next.
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
|
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
ifstream infile("Data.txt");
infile >> Name;
int i,j;
if (infile.is_open())
{
string line;
string Stores[7];
float Sales[7][12];
for (int i = 0; i <7; ++i)
{
if (getline(infile, line))
{
Stores[i] = Name;
cout << Stores[i] << endl;
infile >> Name;
}
}
}
return 0;
}
|