C++ Substring

Hello, thanks for the pervious help in the past. You guys helped me so much

I am trying make a algorithm if it can determine of string1 is a substring of another e.g. is "he" a substring of "hello"

Currently i have done

1
2
3
4
5
6
7
8
9
10
11
12
	//string one will be entered here
	cout << "enter string 1"<< endl;
	cin>>string1;

	//same with string two
	cout << "enter string 2" << endl;
	cin>>string2;

	//just to test 
	cout << string1 << string2 << endl;

	}


which is pretty much the basic lol. Dont know where to start or to find the information. I prefer you guys not doing it but telling me where I can get info for this. Thank you

Would we use somthing like

1
2
3

 if (string1.compare(string2) != 0)


found it at http://www.cplusplus.com/reference/string/string/compare/

edit :that didnt work lol
Last edited on
Try using string::find http://www.cplusplus.com/reference/string/string/find/ and see if "he" can be found in a string that contains "hello".
I seen that one, my brain is telling me its possible by using "size_t find (char c, size_t pos = 0) const;" BUT then it says no lol

The one you use is
size_t find (const string& str, size_t pos = 0) const;
Topic archived. No new replies allowed.