如何检查某人的用户名是否与字符串匹配? [英] How do i check if someone's username matches a string?

查看:78
本文介绍了如何检查某人的用户名是否与字符串匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c ++的新手,我想检查某人的用户名是否与字符串匹配。我试过这个,但它给出了错误。



有人可以帮忙吗?如果有,那么谢谢。



我尝试过:



< pre lang =c ++> TCHAR用户名[UNLEN + 1 ];
DWORD size = UNLEN + 1 ;
if (GetUserName((TCHAR *)username,& size)){
if (username == asd){
// if上的错误(用户名==asd){
}
}





asd意味着它必须与之匹配

解决方案

不要除非你愿意使用带有所有字符串文字的T宏,否则使用TCHAR。



 TCHAR用户名[UNLEN +  1 ] = { 0 }; 
DWORD size = UNLEN + 1 ;
if (GetUserName(用户名,&尺寸))
{
if (_tcsicmp(用户名,_T( asd)== 0
{
// 错误
}
}


Hi, I'm new to c++ and I want to check if someone's username matches with a string. I've tried this but it gives errors.

Can anyone help? If so then thanks.

What I have tried:

TCHAR username[ UNLEN + 1 ];
DWORD size = UNLEN + 1;
if (GetUserName((TCHAR*)username, &size)) {
    if (username == "asd") {
        // error at if (username == "asd") {
    }
}



asd is meant to be the thing it has to match

解决方案

Don't use TCHAR unless you're willing to use the "T" macros with all string literals.

TCHAR username[ UNLEN + 1 ] = {0};
DWORD size = UNLEN + 1;
if (GetUserName(username, &size))
{
    if ( _tcsicmp(username, _T("asd") == 0 )
    {
        // error
    }
}


这篇关于如何检查某人的用户名是否与字符串匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆