我正在尝试获取环境用户名并将文件下载到C:\ username.txt 这是我的代码:
#include <tchar.h>
#include <urlmon.h>
#include <windows.h>
#include <Lmcons.h>
#include <string>
#include <sstream>
#pragma comment(lib, "urlmon.lib")
int main(int argc, char* argv[])
{
TCHAR username[UNLEN + 1];
DWORD size = UNLEN + 1;
GetUserName((TCHAR*)username, &size);
std::string pref;
path = "C:\"+username+".txt";
HRESULT hr1 = URLDownloadToFile ( NULL, _T("http:// example.com/test.txt"), _T(path), 0, NULL );
return 0;
}
但我不知道如何将用户名转换为字符串。我在路径中使用字符串名称时也会出错。但是当我使用“”并且手动编写路径时我没有问题。感谢