I am currently learning C++ and completely newbie to programming. I came across a question and tried solving but ended up with an undesired output. Then with the help of python tutor I tried visualizing the execution of my code , where even after running cin >> q it isn't taking input and displaying an error while executing the next statement where in I tried using the q.
Please, Can anyone tell where is the problem and what makes such errors occur?
Click here to see the problem I tried solving
#include <iostream>
#include<vector>
using namespace std;
int main() {
int q,t1,t2;
vector<int> v;
cin>>q;
while(q--){
if(cin >> t1>>t2){
if(t1==0)
{
v.push_back(t2);
}
else if(t1==1)
{
cout << v[t2] <<"\n";
}
}
else if(cin >> t1){
if(t1==2)
v.pop_back();
}
}
return 0;
}