i'm getting segmentation fault in my code. I've used debugger and pinpoint the error to line 14. It is not storing the input in line 13 and that's why the line 14 throws an out of bounds error. Can anyone tell me why the line 13 is not working?
using namespace std;
#include<iostream>
#include<cstring>
#include<deque>
int main()
{
int n;
cout<<"How many messages to read: ";
cin>>n;
string s;
for(int i=1;i<=n;i++)
{
getline(cin,s); //<-----LINE13
auto it=s.begin(); //<-----LINE14
deque<char> kingdom;
while(s[0]!=',')
{
kingdom.push_back(s[0]);
s.erase(it);
}
s.erase(it);
s.erase(it);
s.erase(it);
while(kingdom.size()!=0)
{
it=s.begin();
for(int j=0;j<s.length();j++,it++)
{
if(kingdom.at(0)==s.at(j))
{
kingdom.pop_front();
s.erase(it);
break;
}
}
}
}
}