C ++ Combine 2 Tchar

I am trying to combine 2 tchar.

char username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserName(username, &username_len);
TCHAR* appdatapath ="C:\\Users\\"+username+"\\AppData";

But I get an error error in the appdatapath line. How can I combine 2 tchar? Thanks

+5
source share
4 answers

Take a look at strcat and wcscat . You cannot add a char pointer with a char array.

If you are on a Windows machine, you can use _tcscatthat will redirect to the desired function to use depending on _UNICODEand _MBCS.

You can also use safe versions by adding _s to the function name.


As pointed out in the comments, you can also use snprintf as follows:

const size_t concatenated_size = 256;
char concatenated[concatenated_size];

snprintf(concatenated, concatenated_size, "C:\\Users\\%s\\AppData", username);

, , , .

+4

: TCHAR, _tcscat.

, : GetUserName LPTSTR, TCHAR . , TCHAR

TCHAR* appdatapath ="C:\\Users\\"+username+"\\AppData";

, , TCHAR , _UNICODE. , , TCHAR ( ) wchar, , , GetUserName wchar_t*, char*. , C- +.

TCHAR _UNICODE defined - wchar . , ++, std::wstring:

wchar username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserNameW(username, &username_len);
std::wstring appdatapath = L"C:\\Users\\";
appdatapath += username;
appdatapath += L"\\AppData";

, : , , SHGetSpecialFolderPath - CSIDL_APPDATA "AppData".

+3
#include <tchar.h>

const size_t stringSize= 20;
TCHAR value[stringSize] = { 0 };

_tcscat_s(value, stringSize, TEXT("appendMe"));

MSDN: _tcscat_s

0
source

Olรก. Most likely, this is the case, and all this requires a special form of resolving problems, such as ... Using utilities for local residents, both for pasta and for a temporary window ... eo nome do meu arquivo ...

TCHAR past_temp[MAX_PATH];
if (GetTempPath(MAX_PATH, past_temp) != 0)
{
    sprintf(past_temp, "%s%s", past_temp, "\Config.ini");
    MessageBoxA(0, past_temp, "Temp path", 0);
}
0
source

Source: https://habr.com/ru/post/1525423/


All Articles