변수를 사용하여 Linux에서 libcurl의 절대 경로를 어떻게 설정할 수 있습니까?C++에서 libcurl을 사용하여 Linux에서 절대 경로를 설정하십시오.
는 여기에 예제 코드입니다 :
}
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
다음을보십시오. http://stackoverflow.com/questions/4329324/c-error-array-must-be-initialized-with-a-brace-enclosed-initializer – iqstatic
도움을 주셔서 감사합니다! – QuestionMan