Jump to content
  • Advertisement
Sign in to follow this  
X_GRAYWOLF_X

Question about strings in C++

This topic is 4412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I am working with some strings now in the book that I got and I came across something I don't understand. if (phrase.find("eggplant") == string::npos) cout << "'eggplant' is not in the phrase.\n\n"; Phrase is Game Over!!! I know that this set of code trys to find the phrase eggplant in Game Over!!! But my main problem is not understanding this: == string::npos What in the world does it mean? O.o

Share this post


Link to post
Share on other sites
Advertisement
string::npos represents a position that is always outside the string. find returns the first position of the phrase "eggplant" which, if it is outside the string, means that the string does not contain the phrase.

Share this post


Link to post
Share on other sites
The find function needs some way to tell you if the search fails. Since it returns an unsinged value, it cannot return -1. So it returns the value string::npos which (on my implementation at least) is about the maximum int vale (4 billion or so).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!