So, i have a piece of code (c++) that gets the users name (in windows) and with the retrieved string the code creates respective directories...
BOOL DirectoryExists(const char* dirName) {
TCHAR nameu[UNLEN + 1];
DWORD size = UNLEN + 1;
if (GetUserName((TCHAR*)nameu, &size))
{
TCHAR* t = nameu;
wcout << t;
//_getch();
std::string str;
std::wstring wStr = t;
str = std::string(wStr.begin(), wStr.end());
usr = str;
dir[0] = (std::string("C:\\Users\\") + str + "\\Documents\\Folder").c_str();
}
DWORD attribs = ::GetFileAttributesA(dirName);
if (attribs == INVALID_FILE_ATTRIBUTES) {
return false;
}
return (attribs & FILE_ATTRIBUTE_DIRECTORY);
}
here, the GetUserName()
functions gets the user name and this piece of code works fine if the user name is just one straight string, but if the usr name had two parts split by space (eg: "example account"), then the code only takes the first part and leaves the 2nd part/name....
how do i solve this ?