網上有專門寫的http下載的C++代碼,可是我發現windows自帶的http下載,一行代碼就搞定,很是簡單,目前爲止使用正常。windows
首先包含頭文件和lib文件url
#include <urlmon.h> //http下載 #pragma comment(lib,"urlmon.lib")
具體使用:spa
HRESULT hr = URLDownloadToFile(0, http_image_path.c_str(), local_image_path.c_str(), 0, NULL) ; if (S_OK == hr) { cout << "HTTP下載保存的臨時地址:" << local_image_path << endl; } else { cout<< http_image_path << "下載失敗!" <<endl; }