一个计数程序报错,编译可以运行错误

新人刚刚学,在编译一个计数出现次数的程序时候,编译时没问题,运行的时候报错了。
不是很明白在哪个位置弄错了,麻烦解答一下
#include
#include
#include
using std::vector; using std::cin;
using std::cout; using std::endl;
using std::sort;
int main()
{
int n;
vector sj;
cout<<"Please input the num:"< while(cin>>n)
sj.push_back(n);
sort(sj.begin(),sj.end());
typedef vector::size_type vec;
vec i=sj.size();
for(int a=0,b=1;a!=i;++a)
{
if(sj[a]!=sj[a+1])
cout<<"the nums of"<<sj[a]<<"is"<<b<<endl;
else
++b;

}
return 0; 

}
图片说明

你的索引越界了

把原来的for循环改一下

    if (i == 1)
    {
        cout<<"the nums of"<<sj[0]<<"is"<<1<<endl;
    }

    int currnetnum = sj[0];
    int count = 1;
    for(int a=1;a!=i;++a)
    {
        if(sj[a]!=currnetnum)
        {
            cout<<"the nums of"<<currnetnum<<"is"<<count<<endl;

            if(a = i - 1)   // 最后一个
            {
                cout<<"the nums of"<<sj[a]<<"is"<<1<<endl;
            }
            else
            {
                currnetnum = sj[a + 1];
                count = 1;
            }
        }
        else
        {
            ++count;
        }

    }