Bom*_*man 0 c++ windows directory download
所以我有这个简单的代码来从打开浏览器的网址下载文件
#include <iostream>
#include<Windows.h>
#include<string>
using namespace std;
int main()
{
string dwnld_URL = "http://www.url.com/downloadpage";
ShellExecuteA(NULL, "open", dwnld_URL.c_str(), NULL, NULL, SW_SHOWNORMAL);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但我希望文件位于当前目录中,而不是默认下载文件夹中。我有什么办法可以做到这一点吗?
如果你在 Windows 上,你可以使用
#include <iostream>
#include<Windows.h>
#include<string>
#pragma comment(lib, "urlmon.lib")
using namespace std;
int main()
{
string dwnld_URL = "http://www.url.com/downloadpage/filename.txt";
string savepath = "C:\\tmp\\filename.txt";
URLDownloadToFile(NULL, dwnld_URL.c_str(), savepath.c_str(), 0, NULL);
return 0;
}
Run Code Online (Sandbox Code Playgroud)