It's not a good idea to erase one element in the loop as the vector size is changing dynamically, which you will easily lose the correct index track.
Instead, try to erase all b
's elements once in the end:
b.clear();
P.S.: There is one easier way to append a vector to another by using std::vector::insert()
so that all you need is:
a.insert( a.end(), b.begin(), b.end() );
b.clear();