Avatar of XK8ER
XK8ER
Flag for United States of America asked on

compare two strings

I would like to compare two string and return true or false..
how do I go about making this work?

Public string daString;

extern "C" bool __declspec(dllexport) 
myCompare()
{
	if (daString == L"6YD01ZH5" | daString == L"5L0BX10HB0")
		return true;
	else
		return false;
}

Open in new window

C++

Avatar of undefined
Last Comment
jkr

8/22/2022 - Mon
farzanj

Use || instead of | in your if condition
XK8ER

ASKER
I get this
      IntelliSense: identifier "daString" is undefined
jkr

The compier is right, it is undeclared in that context. Plus, your function does not take any parameters. Did you mean

#include <tchar.h>

extern "C" bool __declspec(dllexport) 
myCompare(LPCTSTR daString)
{
        // '== 0' means strings are identical
	if (_tcscml(daString ,_T("6YD01ZH5") == 0  || _tcscmp(daStringL,_T("5L0BX10HB0") == 0)
		return true;
	else
		return false;
}
                                  

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
XK8ER

ASKER
how can I declare a string outside the function as public..
something like "public daString as string"
jkr

That'd be a global variable, e.g.

#include <windows.h>
#include <tchar.h>
#include <string>
using namespace std;

string daString; // just a global variable, no 'public' needed

extern "C" bool __declspec(dllexport) 
myCompare()
{
        // '== 0' means strings are identical
	if (_tcscml(daString ,_T("6YD01ZH5") == 0  || _tcscmp(daStringL,_T("5L0BX10HB0") == 0)
		return true;
	else
		return false;
}
                                  
                                            

Open in new window

XK8ER

ASKER
I get this

Error      1      error C2664: '_tcscmp' : cannot convert parameter 1 from 'std::string' to 'const char *'
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
jkr

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
XK8ER

ASKER
there is an issue with this line..

if (daString  == "6YD01ZH5") == 0  || daString == "5L0BX10HB0")

is it supposed to be like this?

if (daString == "6YD01ZH5" || daString == "5L0BX10HB0")
jkr

Yes, you are right - sorry, it is getting late here...