#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <pair<int,int>> s1= {{1,2}, {2,3}, {4,5}, {5,6}};
int x= 10, count;
while (!s1.empty() && s1.back().first <= x )
{
count= count + s1.back().second;
if (s1.back().first== x && s1.back().second== -1)
{
++count;
}
s1.pop_back();
}
for (int i=0; i<4; ++i)
{
cout << s1[i].first << " " << s1[i].second << endl;
}
}
When I run this program, it outputs all the elements originally in the vector s1
. Shouldn't the vector be empty due to the use of pop_back()
?