比较类型char *和wchar_t *的C字符串 [英] Compare C-string of types char* and wchar_t*
本文介绍了比较类型char *和wchar_t *的C字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个key
,例如:
wchar_t key[] = L"764frtfg88fgt320nolmo098vfr";
和数据库查询返回的char* row[i]
.
我想将我的Key
与row[i]
进行比较.我尝试过
I'd like to compare my Key
with row[i]
. I tried with
wcscmp (key,row[i]) != 0)
但是它给了我一个错误.有什么建议吗?
but it gives me an error. Any suggestions ?
推荐答案
这可能会有所帮助:摘要:
#include <string>
wchar_t Key[] = L"764frtfg88fgt320nolmo098vfr";
std::wstring k(Key);
const char* text = "test"; // your row[i]
std::string t(text);
// only works well if the string being converted contains only ASCII characters.
std::wstring a(t.begin(), t.end());
if(a.compare(k) == 0)
{
std::cout << "same" << std::endl;
}
这篇关于比较类型char *和wchar_t *的C字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文