Problem with an array

Dear guys,

How can i solve this problem? You can see the problem in last lines, how can i show the names (for example) which are in a line where day=2? Becouse [i] contains the number of the line, and i must write something into the array. And how i can show the container of a line when there is no number at the begginning of the .txt (like 5 in this example). Sorry, it's very hard to say with my English.

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
41
42
43
44
45
46
47
48
49
50
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct example
{
	int day;
	string name;
};

typedef example array[5];

int load(int& counter, array& something);
int write(array something);

int main()
{
	int counter;
	array something;
	write(something);
        load(counter, something);
	return 0;
}

int load(int& counter, array& something)
{
	ifstream file;
	file.open("file.txt");
	file >> counter; <- #2 PROBLEM
	for(int i=0; i<counter; i++)
	{
		file >> something[i].day;
		file >> something[i].name;
	}
	file.close();
	return 0;
}

int write(array something)
{
	int one=1;
	if(something[one].day)
		cout << something[].name; <- #1 PROBLEM
	else
		continue;
	return 0;
}


file.txt:

1
2
3
4
5
6
5 <- #2 PROBLEM
1 Name
3 Name
2 Name
3 Name
2 Name
Last edited on
I'm trying, but nothing.. :|
Topic archived. No new replies allowed.