not real sure what to call this

what im trying to do is make a program that will kind of... communicate with you, i guess. but the problem i am having is, say for instance, the program says "how was your day?" i want to be able to do something like...
1
2
3
if (response *includes the word* good)
      {
             cout << "well im glad to hear that";

i dont know how to actualy do that. any help is greatly appreciated
Last edited on
read over some of it but im not sure i understand. i havent ever really been able to understand this website's tutorials
That's not a tutorial. That's a concise explanation of what the string class function find does. If you're ever going to get anywhere in programming, you're going to have to be able to read function descriptions.

1
2
3
4
size_t find ( const string& str, size_t pos = 0 ) const;
size_t find ( const char* s, size_t pos, size_t n ) const;
size_t find ( const char* s, size_t pos = 0 ) const;
size_t find ( char c, size_t pos = 0 ) const;

This is a set or prototypes for this function. As you can see, there are four forms of this function. The first one accepts two input variables, one a const string& and the other a size_t object. The size_t input has a default value if you don't provide one.
The other function prototypes are also quite simple.

So now read what he function actually does.

Searches the string for the content specified in either str, s or c, and returns the position of the first occurrence in the string.

Hey, great, that's what you need. You want to look for the word "good". Let's see how we can use this. Let's take the first form.

size_t find ( const string& str, size_t pos = 0 ) const;
This is a class function, so it will be called on an object of type string, like this:

someString.find(str, pos);

Are you following this? Here is a different reference tot he same function: http://en.cppreference.com/w/cpp/string/basic_string/find
Last edited on
Topic archived. No new replies allowed.