Hello
How can i make an if with a text detection? i want to do something like- if the string contains the word "text" do something-
how do i do that?
Thanks.and please don't use very advanced stuff.i mean c++ not C or other complicated things
You're on the right track with using an conditional branch - If statement.
http://www.learncpp.com/cpp-tutorial/52-if-statements/
Now you may to browse the available methods in the string class; part of the standard library.
http://www.cplusplus.com/reference/string/string/
And possibly check the methods in the String operations section.
---
Spoiler:
http://www.cplusplus.com/reference/string/string/find/
and if no string is found, it returns this:
http://www.cplusplus.com/reference/string/string/npos/
int main()
{
string word=;//declare string
//prompt user for entry
cout<<"Please enter a word: ";
cin>>word;//assign user entry to string
if (word=="text")
//do something
else
//do something else
return 0;//terminate program
}
Sure, we could always change line 8 to something like this: if (word=="test" || word=="TEST")
Or, we could convert the string to all upper or lower case before checking.
I think you know what I meant. I thought he was merely checking that the string contained "test" by itself, not checking for the presence of "test" within a string that may also contain other characters.
Rather than the ambiguous phrase "contained alone", consider "only contained". I normally would not push something like this so far but it is clear from this thread that a misuse of words can cause excessive confusion. Now we can avoid confusion in the future :)
Fair enough LB. I don't consider it nitpicking considering you often are attempting to answer questions I have, so if anything can help avoid confusion, it's to the good.