Storing items from file into array

Hey all,
I'm trying to write a code that reads from a tsv file and prints the items, from the date interval entered by the user, in reverse chronological order. I know that I am able to make printing the items in reverse chronological order easier by putting the items into an array, but am unsure as how to go about that. The two kinds of items I'm trying to put in the array are date (string) and specific integers from the tsv file. What I have so far in my code is printing the the dates and their integers specified from the tsv file in normal order.
Any advice on how to put two items into an array would be greatly appreciated!

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
  #include <iostream>
#include <fstream>
using namespace std;

int main()
{
	ifstream fin("Current_Reservoir_Levels.tsv");
	
	string s;
	getline(fin, s);
	
	string date;
	double eastSt, eastEl, westSt, westEl;
	
	bool status;
	cout << "Enter starting date: ";
	string start;
	cin >> start;
	cout << "Enter ending date: ";
	string end;
	cin >> end;
	int inrange=0; //false
	
	while(fin >> date >> eastSt >> eastEl >> westSt >> westEl)
	{	
		if(date==start)
		{
			inrange=1;
		}
		if(date==end)
		{
			inrange=0;
			cout << date << " " << westEl << endl;
		}
		if(inrange==1)
		{
			cout << date << " " << westEl << endl;
		}
	}
}
I'm trying to write a code that reads from a tsv file

You may want to consider a structure to hold the information for each record and a std::vector of this structure to hold each of the records so that you can sort and search the vector for the proper records.



Topic archived. No new replies allowed.