### An array of vector

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

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091`` ``````using namespace std; #include #include #include #include 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,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:"<> n; std::cout<< "Please enter the ID of source:"<> s; std::cout<< "Please enter the ID of sink:"<> t; std::cout<< "Please enter the time horizon:"<> 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::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.