本文介绍了C ++中的lib curl禁用打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 http://curl.haxx.se/中获得了一个小程序,并且在我运行它时总是打印网页如何禁用打印功能
i got a small program from http://curl.haxx.se/ and while i run it always prints the webpage how can i disable the printing function
#include <iostream>
#include <curl/curl.h>
using namespace std;
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,1);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
推荐答案
您需要设置一个CURLOPT_WRITEFUNCTION使其不使用stdout.
You need to set up a CURLOPT_WRITEFUNCTION to make it not use stdout.
这里有一个解释(在CURLOPT_WRITEFUNCTION下): http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
There is an explanation here (under CURLOPT_WRITEFUNCTION):http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
和此处(在处理Easy libcurl下"): http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
and here (Under "Handling the Easy libcurl):http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
基本添加功能:
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
return size * nmemb;
}
并致电
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
应该这样做.
这篇关于C ++中的lib curl禁用打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!