String comparison

Hey guys I'm having some trouble with this program that I'm making, it's a rather large program (for me at least). Currently it's at ~130 lines of code, and at one point I have an 'if' statement where I need the console to compare a user inputed string to see if that inputed string is equal to a predefined list of strings.

if (item1.compare(sword1,sword2,sword3,staff1,staff2,staff3,shield1,shield2,shield3)!= 0 )

The error I am getting is "no matching member function to call to 'compare'" where compare is underlined in the code.
I realize that this might be a problem with my includes:

1
2
3
4
5
6
7
8
9
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include "ItemStats.h" 


However I did some google searches and I found one search that said "The Compare method is primarily intended for use when ordering or sorting strings. You should not use the Compare method to test for equality (that is, to explicitly look for a return value of 0 with no regard for whether one string is less than or greater than the other). Instead, to determine whether two strings are equal, use the String::Equals(String, String, StringComparison) method."

I am not familiar at all with what this means "String::Equals(String, String, StringComparison)"

I am relatively familiar with most c++ code as I've performed TheNewBoston tutorials. Any help would be greatly appreciated, thanks!
I guess that item1 is a std::string. Do you mean if item1 is one of those items do something?

You can compare two string with ==

if I guess right your if statement would look like this:

1
2
3
4
5
if (item1 == "sword1")
...
else if (item1 == "sword2")
...
else ...


I am not familiar at all with what this means "String::Equals(String, String, StringComparison)"
Well, it's .NET and I don't think that you use that...
Last edited on
Topic archived. No new replies allowed.