C++ Http下载文件

C++ Http下载文件

	//HTTP DownloadToFile
	//特别注意:引用头文件和lib库  不然会报错和编译不过
	#include <windows.h>
	#include <tchar.h>
	#pragma comment(lib,"urlmon.lib")
	#pragma comment(lib,"ws2_32.lib")
 
	
	string url = "http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg";
	size_t len = url.length();//获取字符串长度
	int nmlen = MultiByteToWideChar(CP_ACP, 0, url.c_str(), len + 1, NULL, 0);//如果函数运行成功,并且cchWideChar为零,
	//返回值是接收到待转换字符串的缓冲区所需求的宽字符数大小。
	wchar_t* buffer = new wchar_t[nmlen];
	MultiByteToWideChar(CP_ACP, 0, url.c_str(), len + 1, buffer, nmlen);
	HRESULT hr = URLDownloadToFile(NULL, buffer, _T("E:\\sky.jpg"), 0, NULL);
	if (hr == S_OK)
	{
		cout << "Download File Is Success" << endl;
	}

下载结果截图

c++http下载网络图片

猜你喜欢

转载自blog.csdn.net/qq_34940879/article/details/106855341
今日推荐