hello
my problem this time is i have an multidimensional vector and the example of adj vector is showen in the attached picture
and i wanna know the size of each one i mean in i=0 the size is 2
i declare a new vector degree to put in it the size as shown in the code:

vector<int> degree;
for(int i=0; i <n ; i++ )
   {
        degree[i] = adj[i].size();
   }
   cout << "the degree are: \n";
    for (int i = 0; i < n; ++i) {
        cout << degree.at(i) << ", ";
    }

but when i compile it i get this error

any helpful ideas? i'll really appreciate the help thanks in advance :)

Recommended Answers

All 2 Replies

When you're using a vector that doesn't have any elements in it, you can't use the index operator([]) you have to add what you want to put into the vector:

degree.push_back(adj[i].size());

thank you sir that worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.