WiNeNE存储在char/string C++上的读取文件

WiNeNE存储在char/string C++上的读取文件,c++,wininet,C++,Wininet,所以我有这个代码,可以从我的主机上的文本文件中读取一些内容。我通过谷歌搜索得到了这个结果,如果我输入了一个不正确的域名,它就会显示带有错误的messagebox。事情是。。我不知道如何将刚刚读取的信息放入字符串或字符[]。将szBuffer更改为字符[],然后在循环中使用: #include <WinInet.h> #pragma comment(lib, "wininet") void download(std::string domain, std::string url) {

所以我有这个代码,可以从我的主机上的文本文件中读取一些内容。我通过谷歌搜索得到了这个结果,如果我输入了一个不正确的域名,它就会显示带有错误的messagebox。事情是。。我不知道如何将刚刚读取的信息放入字符串或字符[]。将szBuffer更改为字符[],然后在循环中使用:

#include <WinInet.h>
#pragma comment(lib, "wininet")

void download(std::string domain, std::string url)
{
    HINTERNET hIntSession = InternetOpenA("MyApp", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    HINTERNET hHttpSession = InternetConnectA(hIntSession, domain.c_str(), 80, 0, 0, INTERNET_SERVICE_HTTP, 0, NULL);
    HINTERNET hHttpRequest = HttpOpenRequestA(hHttpSession, "GET", url.c_str(), 0, 0, 0, INTERNET_FLAG_RELOAD, 0);
    TCHAR* szHeaders = "";
    CHAR szReq[1024] = "";
    if (!HttpSendRequest(hHttpRequest, szHeaders, wcslen(L""), szReq, strlen(szReq))){
        MessageBoxA(NULL, "No se puede conectar al Servidor de Actualizaciones.", "Error Kundun", MB_OK | MB_ICONERROR);
    }
    TCHAR szBuffer[1025];
    DWORD dwRead = 0;
    while (InternetReadFile(hHttpRequest, szBuffer, 1024, &dwRead) && dwRead)
    {
        // What to do here?
    }
    InternetCloseHandle(hHttpRequest);
    InternetCloseHandle(hHttpSession);
    InternetCloseHandle(hIntSession);
}

download("www.something.com", "File.txt");

我建议你首先阅读所有关于如何从TCHAR转换为。。。先问问题再问另一个问题。我在发帖之前已经看到了很多帖子,我只是想要一些快速帮助><但正如我看到的反对票,我认为人们不喜欢提问:/我理解你的说法,你只是想要一些快速的帮助,因为我太懒了,不愿意自己做任何研究,如果这需要的时间可以忽略不计。
#include <WinInet.h>
#pragma comment(lib, "wininet")

void download(const std::string & domain, const std::string &url)
{
    HINTERNET hIntSession = InternetOpenA("MyApp", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    HINTERNET hHttpSession = InternetConnectA(hIntSession, domain.c_str(), 80, 0, 0, INTERNET_SERVICE_HTTP, 0, NULL);
    HINTERNET hHttpRequest = HttpOpenRequestA(hHttpSession, "GET", url.c_str(), 0, 0, 0, INTERNET_FLAG_RELOAD, 0);
    if (!HttpSendRequestA(hHttpRequest, NULL, 0, NULL, 0))
    {
        MessageBoxA(NULL, "No se puede conectar al Servidor de Actualizaciones.", "Error Kundun", MB_OK | MB_ICONERROR);
    }
    char szBuffer[1024];
    DWORD dwRead = 0;
    std::string data;
    while (InternetReadFile(hHttpRequest, szBuffer, 1024, &dwRead) && dwRead)
    {
        data.append(szBuffer, dwRead);
    }
    InternetCloseHandle(hHttpRequest);
    InternetCloseHandle(hHttpSession);
    InternetCloseHandle(hIntSession);
    // use data as needed...
}