Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contains function for LPCTSTR

Tags:

c++

c

contains

I have a code like:

int contains(LPCTSTR name)
{
   char * data = "test.txt";
}

How can i check whether name contains 'data'? Thanks!

like image 319
Roman Avatar asked Feb 19 '23 22:02

Roman


1 Answers

Since you are using Windows and TCHAR, a more idiomatic solution would be:

BOOL contains(LPCTSTR lpName) {
    return _tcsstr(name, _T("data"));
}

Unless your data is deliberately a char *, in which case the answer changes.

like image 124
Mike Kwan Avatar answered Mar 06 '23 17:03

Mike Kwan