-
string.find()
I thinking of something when using the find() function for a string.
In the code below I am serching for the first occurence of "," in the string
What I wonder is if it is possible to either find "," or the index of the end of the string if there isnīt any "," as in this case.
Code:
int index = 0;
std::string str = "abcde";
index = str.find(",")
-
find returns std::string::npos if the target is not found. So you might check index and assign str.size() to it when not found (you could even wrap calls to find in your own function if you are not happy about the std::string::npos result).
-
I see, thanks for the info! I will try this around a bit.