_getcwd
gets the current working directory.
char *_getcwd( char *buffer, int maxlen );
buffer
storage location for the path.
maxlen
maximum length of the path in characters: char for _getcwd and wchar_t for _wgetcwd.
易知:buffer是路径
maxlen:是长度
功能是得到当前程序的路径
下一个api
urldownloadtofile function
downloads bits from the internet and saves them to a file.
char *_getcwd( char *buffer, int maxlen ); wchar_t *_wgetcwd( wchar_t *buffer, int maxlen );
下面是代码:
#include <windows.h> #include <stdio.h> #include <direct.h> #pragma comment(lib,"urlmon") int main() { char buffer[max_path]; _getcwd(buffer, max_path); strcat_s(buffer, "//1.jpg"); hresult result = urldownloadtofilea(null, "http://112.22.245.11:443/down/de0243d60205717a2a74aea53c0c500c-46353/1.jpg?cts=yd-f-u13274580& ctp=111a23a228a125&ctt=1484747960&limit=1&spd=1300000&ctk=4ab73a4a76e47ad0b181d0f9fc47b6a1&chk=de0243d60205717a2a74aea53c0c500c-46353", buffer, 0, null); switch (result) { case s_ok:printf("the download started successfully.\n");break; case e_outofmemory: printf("the buffer length is invalid, or there is insufficient memory to complete the operation.\n"); break; } return 0; }
程序运行截图:
以上就是 c/c++轻松实现文件下载的内容。