Topic
  • 1 reply
  • Latest Post - ‏2013-11-15T11:50:41Z by JeanZ
GEDARAJASEKHAR
GEDARAJASEKHAR
2 Posts

Pinned topic How to compare two strings in c++ using Rational Rhapsody

‏2013-05-16T11:26:53Z |

 

Hi,
 
    I am executing the below code in Rational Rhapsody 8.0 .I declared and initialized the char* variable. 
 
     char* message = "welcome";
 
     if(message == "welcome")
     {
             std::cout<<"in if case"<<std::endl;
     }
     else
    {      
             std::cout<<"in else case"<<std::endl;
    }
When I generated/build/make the output is showing "In else case".
 
I am expecting the output that  if condition should be satisfied. but to my surprise else condition is executed.
 
So please anyone give me clarification on above example as well as some information regarding operation on char* variables.
 
  AWaiting for your reply,
 
 
 
With Regards,
 
Raja Sekhar Geda,
 
rajasekhar.geda@outlook.com
  • JeanZ
    JeanZ
    1 Post

    Re: How to compare two strings in c++ using Rational Rhapsody

    ‏2013-11-15T11:50:41Z  

    Hi,

    I assume you are using RiC++ model. and the issue you mentioned above should be related to C++ grammer. you can try use strcmp() function in C++  to compare two strings.

    You should find lots of samples related online.

    Regards