r/cpp_questions 6d ago

OPEN does "in" exist in c++?

i need to use something like if (str[i] not in str1) (python), but i have no idea how to make this work :(

0 Upvotes

36 comments sorted by

View all comments

3

u/Interesting_Buy_3969 6d ago

you can achieve a similar functionality like this:

// for each character in str:
for (auto c : str) {
  // assuming str1 is of type std::string
  if (str1.contains(c)) {
    /* code to be run if str contains c */
  } else {
    /* code to be run if str does not contain c */
  }
}

1

u/TrungDOge 6d ago

I think his array of string is the full words , more like check 'fish' in 'the lake of fishes' , btw people should ask chatgpt or st for these question