【发布时间】:2014-11-14 03:23:17
【问题描述】:
如何在 Linux 上的 libcurl 中使用变量设置绝对路径?
这是一个示例代码:
}
string absolute_path = "/home/user_name";
CURL *curl;
FILE *fp;
CURLcode res;
const char *url = "http://google.com";
const char outfilename[FILENAME_MAX] = absolute_path;
curl = curl_easy_init();
if (curl)
{
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
但是编译器返回这个错误:
error: array must be initialized with a brace-enclosed initializer
有人知道怎么解决吗?感谢您的关注!
【问题讨论】:
-
const char outfilename[FILENAME_MAX] = absolute_path;这行肯定是不正确的。实际上,您不需要outfilename变量。在fopen()中使用absolute_path.c_str() -
感谢您的帮助!
-
解决了你的问题吗?
-
我已经通过 user3159253 的回复解决了我的问题。