How do i compare two objects in a string?

Oct 11, 2012 at 6:38pm
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
Oct 11, 2012 at 6:44pm
OP wrote:
compare both of these strings

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

HTH,
Aceix.
Oct 11, 2012 at 7:20pm
yes i did but it doesnt work, it doesnt tell me where to exactly put the right parts of code... please help
Oct 11, 2012 at 7:41pm
Well, so far you don't have any "parts of code"...

If you were to supply some, you might have more success getting help.
Oct 11, 2012 at 7:53pm
My Main.cpp
[code]#include <iostream>
#include <string>
#include <string.h>
using namespace std;

Last edited on Oct 25, 2012 at 6:37pm
Oct 11, 2012 at 8:01pm
What is a WCS_String?
Oct 11, 2012 at 8:04pm
its the code
Last edited on Oct 25, 2012 at 6:38pm
Oct 11, 2012 at 8:09pm
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?
Oct 11, 2012 at 8:26pm
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?
Oct 11, 2012 at 8:58pm
Name has a compare function. Maybe you should implement it.
Oct 11, 2012 at 9:02pm
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
Oct 11, 2012 at 9:05pm
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?
Oct 11, 2012 at 9:09pm
hmm.. sry i am really confused.. i wish i could help u with more parts.. but i have nothing else
Oct 11, 2012 at 9:10pm
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
Oct 11, 2012 at 9:26pm
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?
Oct 11, 2012 at 9:30pm
we sort them?
Oct 11, 2012 at 9:34pm
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?)
Oct 11, 2012 at 9:38pm
hmmm
Oct 11, 2012 at 9:43pm
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 Oct 11, 2012 at 9:44pm
Topic archived. No new replies allowed.