1
struct node {
  char name_;
  vector<node*> nbs_;
};

node a, b, c;
  a.name_ = 'a';
  b.name_ = 'b';
  c.name_ = 'c';
  a.nbs_.push_back(&b);
  a.nbs_.push_back(&c);

  for (vector<node*>::iterator i = a.nbs_.begin(); i != a.nbs_.begin(); i++) {
    cout << (*i)->name_;
  }

Why isn't the above code working. It prints nothing. I wanted it to print node b's and c's name.

0

1 Answer 1

13
i != a.nbs_.begin();

should be

i != a.nbs_.end();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.