Looking for a string member fuction
Hey, folks, I just joined the community, and I come with a question about the string class.
I've mostly been teaching myself C++ over the last several years, (I took one class for credit, but it didn't teach me anything new) and for a while I used only the null-terminated character arrays from C and kind of got used to manipulating them. More recently I've started using actual C++ strings, since they are less prone to errors, but I don't have a lot of documentation on them, and I don't know all the functions.
I have a member function I'm writing that takes a string as an argument, determines whether or not said string exists anywhere in a certain string member variable of the class, and if not, appends it. I've found a member function of string called "find" which returns the index of the start of the location of the one string within the other string, but its return value seems to be undefined when it doesn't find the substring. Since this is usually a large number, I've hacked it together with
to determine that the substring is not in the member variable, but is there a better (100% accurate) way of doing this?
I've mostly been teaching myself C++ over the last several years, (I took one class for credit, but it didn't teach me anything new) and for a while I used only the null-terminated character arrays from C and kind of got used to manipulating them. More recently I've started using actual C++ strings, since they are less prone to errors, but I don't have a lot of documentation on them, and I don't know all the functions.
I have a member function I'm writing that takes a string as an argument, determines whether or not said string exists anywhere in a certain string member variable of the class, and if not, appends it. I've found a member function of string called "find" which returns the index of the start of the location of the one string within the other string, but its return value seems to be undefined when it doesn't find the substring. Since this is usually a large number, I've hacked it together with
if (membervariable.find (substring) > membervariable.len ())
to determine that the substring is not in the member variable, but is there a better (100% accurate) way of doing this?
