Question about "not include"

I know you can do (string.find ("good") !=std::string::npos to do a include thing. But is there a way to do the oposite of it? An if it doesn't include command.
==std::string::npos ...
closed account (3hM2Nwbp)
"Include Thing"

I'm interpreting this as to whether a string contains a provided sequence or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>

int main()
{
  std::string hello = "Hello!";
  std::cout <<
    hello << 
    // print "true" if hello does not contain "Hello"
    hello.find("Hello") == std::string::npos ? "true" : "false" <<
    // print "true" if hello does contain "Hello"
    hello.find("Hello") != std::string::npos ? "true" : "false" <<
  std::endl;
}

Hello!
false
true

Last edited on
Topic archived. No new replies allowed.