As you will see above, pop_back doesn't accept any arguments, instead it just deletes the very last element in a container, no matter where the iterator is, or in your case where the pointer arithmetic puts it.
He's using pointer arithmetic on that input, though, which indicates that he's trying to delete a certain element based on the beginning of the vector plus however many entries the user indicates, potentially by choosing a book that was displayed in the loop for displaying the names of the books already contained in the vector.
cipher is right, i'm trying to have the user enter the selected book out of the ones displayed then it deletes that specific booking, when i do .erase it erases all of the bookings, not just the user entered one.
is there another function of vector i can use? or is there a way to do what i said above?
the vector isnt empty, it isnt the loop<size, it just doesnt display the bookings that are in there once you remove one booking; however it is still viable to enter 0,1,2....etc.
#include <iostream>
#include <vector>
class Bookings{
public:
Bookings(){}; // Empty constructors should be defined in-line.
~Bookings(); // Define a constructor, define a destructor.
string name;
void display_name();
};
void Bookings::display_name() // Put a return type on your functions
// and put them outside of main.
{
std::cout << name << endl;
}
int main()
{
vector<Bookings> BookingsVector; // Vector in main.
vector<Bookings>::iterator it; // Iterator for the vector.
std::cout << "Welcome to the edit booking menu!" << endl << "select booking" << endl;
for (int i = 0; i < BookingsVector.size(); ++i){ // For loop does what your
// while loop does, but cleaner.
std::cout << "[" << i << "]";
BookingsVector[i].display_name();
}
std::cin >> book_name_select; // Get user input.
it = BookingsVector.begin()+book_name_select; // Set the iterator.
it.erase(); // Erase the record.
}