How do i compare two objects in a string?

Please help
If i have :

String K1 (R3, R1, R2);
String K2 (R6, R4, R5);

Please help on how to compare both of these strings.. (R1 for example has first name, R2=Middle, R3=Last) But both strings are different if you notice the R_

What should i put under my string class and main.cpp
OP wrote:
compare both of these strings

I suggest you take a look at the string::compare() function.

HTH,
Aceix.
yes i did but it doesnt work, it doesnt tell me where to exactly put the right parts of code... please help
Well, so far you don't have any "parts of code"...

If you were to supply some, you might have more success getting help.
My Main.cpp
[code]#include <iostream>
#include <string>
#include <string.h>
using namespace std;

Last edited on
What is a WCS_String?
its the code
Last edited on
if (N1.compare (N2) == 0)

So, your compiler tells you that there is no compare function for WCS_String... because there is no compare function for WCS_String. There is, however, a Compare function. There is also an operator==. Who knew you could find this stuff by looking in a header file?
cire, but the problem is when i put this code for comparison or the if statement then it says that Name.h doesnt have compare... how can we make it look from the WCS_STRING?
Name has a compare function. Maybe you should implement it.
yes.. cire, you got it.. thats my problem.. trying to do it ...but not working.... for some reason.. dont know what i am doing wrong.. i tried string:compare thread....still no hope
Well, again, you aren't showing the relevant "parts." How have you tried to implement it? Why would you use std::string methods when no std::string is involved?
hmm.. sry i am really confused.. i wish i could help u with more parts.. but i have nothing else
what i have to do is : Create a Name class composed of three String objects (for First, Middle, and Last). Provide methods and operators for comparing Names, reading and writing Names, and for allowing the retrieval and changing of the components of a Name (i.e. Get and Set methods for First, Middle and Last).

I dont get this compare part
If you're looking at two names on a piece of paper in front of you. How do you determine which name comes before another?
we sort them?
You're putting the cart before the horse. How do you compare them to know which comes before the other (which you must do in order to sort them?)
hmmm
Let's approach this from a different angle.

Suppose you have a phone book, and you're looking for a name.

Suppose you're looking for the name Boaz, George C, but you open the phone book and the first name you see is Phillips, Michael A.

When you look at that name, what is the relevant portion for deciding whether the name you're looking for is ahead of or after the name you opened it to? Is it the first name or the middle initial you start with?
Last edited on
Topic archived. No new replies allowed.