An array of vector

Hi,my program does not work, can anybody help me?

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using namespace std;
#include <iostream>
#include <fstream>
#include <array>
#include <vector>
class arc
{
	// const int M=1000000;
public:
	arc(int Id=0, int co=1000000, int tr=1000000) : ID(Id), cost(co), transit_time(tr) {}

	int ID; // The tail(nodes) or head(B) of arc.
	int cost;
	//int cost_scaled;
	int transit_time;
};

class Network{
public:
	std::array<std:: vector<arc>,4> nodes;
	 int n; //number of nodes.
	 int s; //source
	 int t; // sink
	 int T; //time horizon
	void nodes_initials();
	void create_Network();
	void add_arc_nodes(int , arc );
	void print_cost();
};

void Network::nodes_initials(){

	
	std::cout<< "Please enter the number of nodes:"<<endl;
	std::cin>> n;
	std::cout<< "Please enter the ID of source:"<<endl;
	std::cin>> s;
	std::cout<< "Please enter the ID of sink:"<<endl;
	std::cin>> t;
	std::cout<< "Please enter the time horizon:"<<endl;
	std::cin>> T;
	//nodes=new arc *[n+1];
	//B=new arc *[n+1];
	//for (int i=0; i<=n; i++)
	//{
	//	nodes[i]=new arc;
	//	B[i]=new arc;
	//}
}
void Network::add_arc_nodes(int i, arc a) // i is the head of arc a.
{
	nodes[i].push_back(a);

}
void Network::create_Network() // read the network's parameter  from data file.
{
	int i;//head of arc.
	int j;//tail of arc.
	int co;// cost of arc.
	int tr; //transit time of arc.

	ifstream file;
	file.open("Data.txt", ios::in);
	while(file >> i >> j >> co >> tr)
	{
		arc a(j, co, tr);
		add_arc_nodes(i,a);
	}
	file.close();
}
void Network::print_cost()
{
	for(int i=0; i<4; i++)
      {for (std::vector<arc>::iterator it = nodes[i].begin() ; it != nodes[i].end(); ++it)
         std::cout << ' ' << *it->cost;
        	std::cout << '\n';
     	}
  std::cout << '\n';
}



int main()
{ Network x;
int i;
x.nodes_initials();
x.create_Network();
x.print_cost();
std::cin>>i;
return 0;
}


The Data.tex file is as follows:
1 2 5 6
1 3 4 5
2 3 1 4
2 4 3 2
3 4 4 3

where each row represents an arc, the second column is "tail", the third is "cost" and the forth is "transit_time"
Topic archived. No new replies allowed.