views:

48

answers:

2

i have created a win32 window it work fine but im tryin to get command argument using lpcmdline. it works fine but when i try to compare it to string it to does work here is the comparing code

TCHAR checking[]=_T("hello"); 
if(args==checking) // args equals lpcmdline like this LPTSTR args=lpcmdline
{
    TCHAR greeting[]=_T("heys");
}
else
{
    MessageBox(NULL,args,L"1",MB_OK);
    /*if args doesn't equal checking tha cout what is inside args*/
    MessageBox(NULL,checking,L"2",MB_OK);
    //cout checking
}

well when i cout both varabiles they are the same like args output is hello and checking output is hello but i don't know why they don't get equaled please help thanks in advance

+3  A: 

That's not the right way to compare two strings in C++.

Given that you're comparing a TCHAR array with an LPTSTR, call _tcscmp instead of using the == operator.

Tim Robinson
+2  A: 

if(args==checking) compares the pointers args and checking. Since they are pointing at different places the condition is not satisfied. What you want is a string comparison, for that you need to use function like _tcscmp.

Naveen