2011-08-23 99 views
9

將「res」變量(CURLcode)轉換爲CString最簡單的方法是什麼?C++ LibCurl - 將CURLcode轉換爲CString

下面是在我的機器上編譯好的標準示例,但我想在MFC應用程序中使用它並將結果顯示爲MessageBox。任何幫助表示讚賞!

#include <curl/curl.h> 

int main(void) 
{ 
    CURL *curl; 
    CURLcode res; 

    curl = curl_easy_init(); 
    if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); 
    res = curl_easy_perform(curl); 

    /* always cleanup */ 
    curl_easy_cleanup(curl); 
    } 
    return 0; 
} 

回答

8

可以使用curl_easy_strerror功能。

CString str(curl_easy_strerror(res)); 

CString str; 
str.Format("curl_easy_perform return %s [%d]",curl_easy_strerror(res),res); 
+1

看來你需要首先使用curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,myBuffer),它基於http://curl.haxx.se/libcurl/c/curl_easy_setopt.html – Suma

1

一個CURLcode是一個數字,所以以後在谷歌4秒鐘,然後從來沒有使用過MFC,我發現你可以這樣做:

CString str; 
str.Format("%d", res); 
+0

顏色我尷尬。謝謝 – kogh

+2

@kogh第二個答案可能會好很多,轉換成一個合理的字符串,而不是一個數字。 – Suma