1
#include "stdafx.h"
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <iostream>
#include <UrlMon.h>
#include <cstring>
#pragma comment(lib, "UrlMon.lib")
using namespace std;

int main()
{
char* appdata = getenv("APPDATA"); //Gets %Appdata% path
char* truepath = strcat(appdata, "\\USR\\file.dat"); // file location

cout << truepath ;
HRESULT hr = URLDownloadToFile(NULL, _T("http://localhost:8080/upload.php?name=Huh?" + truepath), _T("d"), 0, NULL);
cin.get();
return 0;
}

これは上記のコードで、このレーンでエラーが発生します。

HRESULT hr = URLDownloadToFile(NULL, _T("http://localhost:8080/upload.php?name=Huh?" + truepath), _T("d"), 0, NULL);

それが私に与えているコンパイルエラーは、「+ truepath」はそこで使用できないと言っています。

.c_str() と他のいくつかの方法を試しましたが、うまくいきません。どんな助けでも大歓迎です。

4

2 に答える 2

4
// ANSI Build
std::string appdata( getenv("APPDATA") ); 
appdata += "\\USR\\file.dat";
std::string url( "http://localhost:8080/upload.php?name=Huh?" );
url += appdata;
URLDownloadToFile( NULL, url.c_str(), [...] 

// UNICODE Build
std::wstring appdata( _wgetenv( L"APPDATA" ) ); 
appdata += L"\\USR\\file.dat";
std::wstring url( L"http://localhost:8080/upload.php?name=Huh?" );
url += appdata;
URLDownloadToFile( NULL, url.c_str(), [...] 
于 2013-12-19T13:25:19.300 に答える