I'm new at C++ coding, and I have this code:
std::string user_name = "raso";
// User Name
TCHAR username[UNLEN + 1];
DWORD username_len = UNLEN + 1;
GetUserName((TCHAR*)username, &username_len);
if (user_name == username)
{
std::cout << "You found the user name!";
}
It gives me an error. It basically finds the user name of the PC and compares it with the string user_name, but user_name is a std::string and username is a TCHAR* type, right? So, how can I compare both in an if statement?
Don't mix-and-match wide and narrow strings.
If your target name is
std::string, use anAversion of API: GetUserNameAAlso, your type casting
(TCHAR*)usernamewas not needed.