C++ LibCurl - 将 CURLcode 转换为 CString

标签 c++ libcurl cstring

将“res”变量 (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;
}

最佳答案

您可以使用 curl_easy_strerror 函数。

CString str(curl_easy_strerror(res));

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

关于C++ LibCurl - 将 CURLcode 转换为 CString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7164654/

相关文章:

c++ - 无法调用纯抽象基类重载

curl - 哪个 HTTP 库更好? Wget、cUrl、LibWWW 还是……?

c - 如何附加到从 libcurl 下载的文件?

C++ 字符串到固定大小的 char 数组可能吗?

c++ - 从派生类调用父类成员函数

c++ - 如何在 O(n) 运行时间内从答案中删除重复项?

c++ - Opencv hough圆圈未检测到圆圈

c++ - libcurl curl_easy_perform() 在函数内部移动时导致程序崩溃

C++,OpenGL : Weird problem with c-strings

c# - C# 中的 C++ CString 等价物