I'm currently concantenating an array like so...

int _tmain(int argc, _TCHAR* argv[])
{
    //create buffer to receive path
    WCHAR pathbuf[MAX_PATH];
    //get path into buffer
    DWORD pathlen = GetCurrentDirectoryW(MAX_PATH,pathbuf);
    //append file name to buffer
    pathbuf[pathlen++] = '\\';
    pathbuf[pathlen++] = 'f';
    pathbuf[pathlen++] = 'i';
    pathbuf[pathlen++] = 'l';
    pathbuf[pathlen++] = 'e';
    pathbuf[pathlen++] = '.';
    pathbuf[pathlen++] = 'e';
    pathbuf[pathlen++] = 'x';
    pathbuf[pathlen++] = 't';
    pathbuf[pathlen++] = '\0';

    std::wcout << pathbuf << std::endl;
    std::cout << pathlen << std:: endl;

    return 0;
}

How can I do this a little less cumbersome?

Recommended Answers

All 2 Replies

How about wstrcat?

wstrcat (pathbuf, L"file.ext");

Thanks for the suggestion, I ended up after following links from your offer to use wcsncat

int _tmain(int argc, _TCHAR* argv[])
{
    //create buffer to receive path
    WCHAR pathbuf[MAX_PATH];
    //get path into buffer
    DWORD pathlen = GetCurrentDirectoryW(MAX_PATH,pathbuf);
    //append file name to buffer
    WCHAR * filename = L"\\file.ext\0";

    wcsncat( pathbuf, filename, 9 );

    std::wcout << pathbuf << std::endl;
    std::cout << pathlen << std:: endl;

    return 0;
 }

Is this the correct usage? I mean with "filename 9" will this result have terminating character?

(edit) OK I think I found solution, please advise if you think it incorrect usage.

wcsncat( pathbuf, filename, wcslen(filename));

Thank you for help.

sorry, I can not find button to mark as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.