The function gets the name, how can I check the contents of this name for such characters as: '' |; "\ //] [

  • Are you not from PHP? > well, if the nickname of the vehicle does not end with the web, the chances are quite high :) and I was already convinced by the tags :) - mega
  • @mega: well, if the nickname of the vehicle does not end with the web, the chances are pretty high :) @avengerweb: welcome to the world of C ++! - VladD
  • one
    > welcome to the world of C ++! to the world that is very cruel to emigrants from php))) - DreamChild
  • I really get it :) - avengerweb
  • one
    @DreamChild You are too verbose. Easier to say in a world that is very cruel - alexlz

1 answer 1

Use find_first_of :

 if (s.find_first_of("'|;\"\\/][") != std::string::npos) { // gotcha! 

Take out the discussion in the comments.

As @avp rightly notes (thanks!), The find_first_of implementation may be slower than the older library function std::strpbrk . If you have a performance find_first_of due to a frequent call to find_first_of , try this:

 if (strpbrk(s.c_str(), "'|;\"\\/][")) { // gotcha! 

For wchar_t strings, use the “wide” analogue of wcspbrk .

  • Is it a cycle? Does he check the first character? - avengerweb
  • No, no loops, this code searches for all characters in the entire string s . - VladD
  • All understood, thanks - avengerweb
  • one
    Please note that it can get lost after a single word find_first_of And do not forget to look at the graphs at the end of the page. - avp
  • 2
    @VladD, why manually? strpbrk () from the Sichnaya IMHO library should work everywhere. You look at the results. - avp pm