std::set<std::string> setStrings;
setString.insert("abc");
setString.insert("abcd");
setString.insert("babc");
Question> I would like to know how to check whether “bab” is one of the stored string’s prefix?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume you don’t want to search the entire set: just use
std::set<std::string>::lower_bound()and iterate until you find astd::stringwhich doesn’t have the desired prefix:If you just want to find if there is one string with the corresponding prefix you can use the condition as in the loop.