I keep getting the error: Vector subscript out of range . I've spend an hour trying to find out why I keep getting it , it might be something obvious but I can't see it . From the trial and error trying to find out where is the problem I managed to narrow it down to the second while() but still . Any help is welcomed . Thanks.
fstream text("text.txt",ios::in);
vector <char> arr;
vector <int> freq;
char a;
if(!text)
{
cout<<"\nError!\n"<<endl;
return;
}
else
{
//-------------//initializing first element of each vector
text>>a;
arr.push_back(a);
freq.push_back(1);
//-----------//
while(!text.eof())
{
text>>a;
unsigned i=0;
while(a != arr[i] && i < arr.size())
i++;
if(i < arr.size())
freq[i]++;
else
{
arr.push_back(a);
freq.push_back(1);
}
}}