comparing string with item

Hi all,

is there any way to compare string item, say given form in stream, with an object name.

Consider the following code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

struct st{};

int main(){
st TestObject;
string STR;
cin >> STR >>endl;

// procedure or code to compare ONLY the NAMES of string and objects. 
// if(TestObject == STR
 )  
...
}



Any suggestion!!
What do you mean the "names" of st objects? That struct has no members to look at.
Like this?

1
2
3
4
if(STR == "TestObject")
{
  ...
}
closed account (10oTURfi)
I think I know what he is trying to tell.

You cannot compare an objects identifier with string.
However what you can do is add a object of type string to class st, which will be the name of objects, then you compare if TestObject.name == "TestObject"
Last edited on
@krofna: You are right... That was what I am trying to say.

However, I should mention what is about if can not modify the class declaration by adding new member variable.

So how can I compare the objects identifier with an string?

Any suggestion?
I suppose it cannot be done , please correct me if i am wrong .
closed account (10oTURfi)
@mar11

that is not possible
Topic archived. No new replies allowed.