error-abort() has been called! help!

#include<iostream>
#include<string>
using namespace std;

class Player{
string user;
public:
void setuser();
string getuser();
};

void Player::setuser(){
cout<<"player>>";
cin>>user;
}

string Player::getuser(){
return user;
}
class WordGame{
string firstword;
string secondword;
public:
void setword(string text1, string text2);
int compareword();
string secgetword();

};
void WordGame::setword(string text1, string text2){
firstword = text1;
secondword = text2;
}

int WordGame::compareword(){
if(secondword.at(0)==firstword.at(4)&&secondword.at(1)==firstword.at(5))
return 1;
else
return 0;
}

string WordGame::secgetword(){
return secondword;
}




int main(){
int i;
int b=1, choice;
cout<<"play :: (number)";
cin>>i;
WordGame *game = new WordGame[i];
Player *gameuser = new Player[i];

for(int a=0; a<i; a++){
gameuser[a].setuser();
}

string startword = "father";
cout<<"start word : father "<<startword<<endl;
cout<<gameuser[0].getuser()<<">>";
string strword;
cin>>strword;
game[0].setword(startword, strword);
choice=game[0].compareword();

if(choice !=1)
cout<<gameuser[0].getuser()<<" lose....";
while(1){
cout<<gameuser[b%i].getuser()<<">>";
cin>>strword;
game[b%i].setword(strword,game[(b+(i-1))%i].secgetword());
choice=game[b%i].compareword();
if(choice != 1){
cout<<gameuser[b%i].getuser()<<" lose....";
getchar();
getchar();
return 0;
}
b++;
}

delete []gameuser;
delete []game;
}

I don't know why this error occurred.

debug error : R6010-abort() has been called

How should I fix it? :(
The function compareword() looks a bit suspicious. If you want to compare if two strings are equal you can use the == operator.

 
if (firstword == secondword)
compareword() function that korea word chain.
The problem is on line if (secondword.at(0) == firstword.at(4) && secondword.at(1) == firstword.at(5)) if firstword is shorter than 6 you get an out_of_range error.

@Peter87,
he/she doesn't compare the whole string.
Topic archived. No new replies allowed.