bool StringsEqual(string Str1, string Str2)
{
if (Str1.size() != Str2.size()) //If the sizes of the strings are different.. then they are of course not the same..
return false;
for (unsigned I = 0; I < Str1.size(); I++) //We established they are the same size if we got this far..
{
if (Str1[I] != Str2[I]) //If at least 1 character in the strings are different, then they are of course not the same..
return false;
}
return true; //If all else succeeded then the strings are definitely the same..
}
triumphost
Practically a Master Poster
625 posts since Oct 2009
Reputation Points: 59
Solved Threads: 55
Skill Endorsements: 1
I am currently trying to use the .compare() but it doesn't seem to be working can someone help me out it would be much appreciated.
which part are you trying to compare?
Did you check already how compare works?
if not this link might help http://www.cplusplus.com/reference/string/string/compare/
zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14
The reason why the code that you posted doesn't work is because the champ_type string that you obtain from the user and the one that is inside the object "obj" are not the same. The one you obtain from the user is a local variable in the main() function, which is not the one inside the object "obj".
If you move the obj initialization (line 85) to after you get the input from the user (after line 102), all should work as expected.
mike_2000_17
21st Century Viking
3,144 posts since Jul 2010
Reputation Points: 2,062
Solved Threads: 626
Skill Endorsements: 41