mardi 27 juin 2023

C string find always returning not found [closed]

I'm trying to find a string in a vector of strings. So I'm doing

vector<int> exists(vector<string>G, int row, int column, string p){
    vector<int>pos;  
    for(int i = row; i < G.size() ; i++){
        string x = G[i];
        if(x.find(p) != std::string::npos){
            if(row == 0){
                pos.push_back(i);
                pos.push_back(x.find(p));
            }
            else {
                if(x.find(p) == column){
                    pos.push_back(i);
                    pos.push_back(x.find(p));
                }
            }
            return pos;
        }
    }
    
    return pos;
}

For example I've this gird: 1234567890
0987654321
1111111111
1111111111
2222222222

and I'm trying to find 876543

But find() is always returning std::string::npos. Is there something wrong here or should be done differently?

Aucun commentaire:

Enregistrer un commentaire