Hello again guys,
I've got kind of a noob question.
I have a wchar[260] and I need to compare it with a char*
and im getting the error
error C2664: '_stricmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'
Thanks!
Hello again guys,
I've got kind of a noob question.
I have a wchar[260] and I need to compare it with a char*
and im getting the error
error C2664: '_stricmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'
Thanks!
ran into a type-mismatch: WCHAR[260] (wide characters) cannot be passed to _stricmp, which expects const char *. is right that the simplest immediate fix on MSVC is to use the wide-character variant _wcsicmp. That avoids changing your buffer type and does a case-insensitive compare on wchar_t strings.
A minimal example using _wcsicmp:
#include <wchar.h>
WCHAR a[260] = L"Hello";
WCHAR b[260] = L"hello";
if (_wcsicmp(a, b) == 0) {
// match ignoring case
} If the other string you need to compare is a char*, convert one side to the same character type instead of trying to compare directly. Converting the narrow string to wide (recommended on Windows) with MultiByteToWideChar:
#include <windows.h>
#include <wchar.h>
WCHAR wideBuf[260] = L"...";
const char *narrow = "someText";
WCHAR tmp[260];
if (MultiByteToWideChar(CP_UTF8, 0, narrow, -1, tmp, sizeof(tmp)/sizeof(tmp[0])) != 0) {
if (_wcsicmp(wideBuf, tmp) == 0) { /* equal */ }
} Notes and cautions: choose the code page (CP_UTF8 vs CP_ACP) depending on whether the char* is UTF-8 or ANSI. _wcsicmp and _stricmp are Microsoft-specific; portable code needs alternatives (e.g., wcscasecmp on POSIX, or use UTF-8 std::string with a locale-aware comparison, or libraries like Boost/ICU). If you use TCHAR and want to toggle between ANSI/Unicode builds, prefer _tcsicmp and the generic-text macros. ’s suggestion to post code was useful — if there are still problems, check which encoding the char* actually uses and post that snippet.
Jump to Post— Narue 5,707error C2664: '_stricmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'
That's a perfectly rational error. Your string is of type WCHAR and _stricmp clearly only accepts strings of char. On the assumption that you're using a compiler which supports it, try _wcsicmp instead of _stricmp.
How are we going to know that what mistake have you done. Write the code here and i would definetly try to guide you. .
error C2664: '_stricmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'
That's a perfectly rational error. Your string is of type WCHAR and _stricmp clearly only accepts strings of char. On the assumption that you're using a compiler which supports it, try _wcsicmp instead of _stricmp.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.