mardi 25 décembre 2018

segmentation fault in cin proccess

void Room::join(){
 try{
    check_input_arguments();
    bool enter_not_pressed = true;
    string name;
    char c;
    int counter = 0 ;
    while(enter_not_pressed){
        cin >> name ;
        counter ++ ;
        name_of_players.push_back(name);
        cin.get(c);
        enter_not_pressed = (c!='\n');
        cout << counter;
       }
    if(name_of_players.size() > get_num_of_roles()){
        for(int i=0 ; i < counter ; i++)
            name_of_players.pop_back();
        throw too_many_users();
       }
    if(name_of_players.size() == get_num_of_roles()){
        give_random_roles();
       }
    }
   catch(few_arguments ex){
        cerr << "You didn't enter enough arguments!" << endl;
    }
   catch(too_many_users ex){
    cerr << "many users" << endl;
    }
}

I write this method for Room class , when i want to receive number of strings equivalent to get_num_of_roles() i encounter with segmentation fault error, but this code is working for number of strings more than get_num_of_roles(printing "too many" users) and less than get_num_of_roles(do nothing). Help me please , Thank you guys!

Aucun commentaire:

Enregistrer un commentaire