mardi 9 juillet 2019

Why is string::find's behavior different?

bool check_tape(char* tape) {
    int test8; 
    cout << example <<" "<<example.size()<<" "<<alpha_sym<<" "<< endl;
    cin >> test8; //To pause the program, temporary 
    int err = 0;
    for (int i = 0; i < example.size(); i++) {
        if (alpha_sym.find(example[i]) >= 0 && alpha_sym.find(example[i]) < example.size()) {
            cout << alpha_sym.find(example[i]) << " " << endl;
            err += 0;
        }
        else {
            cout << example[i]<<" "<< i << " не содержится в алфавите" << endl;
            err++;
        }
    }
    if (err) {
        return 1; //Temporary I made here return 1, else program will crash 
        //get_acmd();
    }
    else return 1;
}

In one case, find returns a position of the first entry as expected, but in other case it returns char itself.
111+11 - string, and chars from it are searching in the other string "1+_"

Same with 1435+212 and 01234567+_

Good case

Strange case

Aucun commentaire:

Enregistrer un commentaire