for (auto& e : persons)
{
staticint n = 1;
cout << right << setw(3) << n++ << " "
<< left << setw(20) << e.firstname
<< setw(20) << e.lastname << '\n';
}
Declare n as static so it retains its value from one iteration to the next. (You could declare it outside the loop, but that is cluttering the outer scope with unnecessary variables).