Having trouble sorting the data in the input file into the designated array. The input file contains a string, double, and int.
- TN 54.5 7
- KY 65.6 23
- PA 123.3 30
- etc.
There are 14 lines of type string, double, int data types. The data is to be printed to screen in the same format as the file. I have been able to print the data to the screen using one 'string array' but the data does not print in the order specified above. I have tried using getline() and through research saw many talking of using simply 'input >> variable[max];' for each individual variable. This only prints a huge number and the number 53 niether of which are contained in the input file. I feel like i am making this harder than it is. I know that my array is to small to read the amount of data needed (that i plan to fix). Not asking for someone to figure this out for me. Just need to be pointed in the right direction. Is there an easier way to sort the data to desired array?
The code below is what i used with one array to read all data types.
#include <iostream>
#include <fstream>
using namespace std;
void readData(ifstream& input, string []);
int main()
{
string data[14];
char filename[256];
fstream input;
cout << "Enter file name: ";
cint >> filename;
input.open(filename);
if (input.fail())
{
cout << "opening file fail." << endl;
}
readData(input, data);
input.close();
return(0);
}
void readData(ifstream& input, string data[14])
{
int count;
count = 0;
while (count < 14 && !input.eof())
{
input >> data[count];
count << data[count] << endl;
count++;
}
}