我找到了相同的代码来从 C++ 的网页中读取数据。就像这样:
#include <iostream>
#include <string>
#include <C:\curl\curl.h>
// Right path, I am sure.
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main(void)
{
CURL *curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
std::cout << readBuffer << std::endl;
}
return 0;
}
但它没有按预期工作。这是错误消息:
1>------ Build started: Project: deneme, Configuration: Debug Win32 ------
1> deneme.cpp
1>deneme.obj : error LNK2019: unresolved external symbol __imp__curl_easy_cleanup referenced in function _main
1>deneme.obj : error LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function _main
1>deneme.obj : error LNK2019: unresolved external symbol __imp__curl_easy_setopt referenced in function _main
1>deneme.obj : error LNK2019: unresolved external symbol __imp__curl_easy_init referenced in function _main
1>C:\Users\nazif\Documents\Visual Studio 2010\Projects\deneme\Debug\deneme.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我怎样才能解决这个问题?
基本上,我想在我的 C++ 代码中使用 curl 来获取某个网页的内容。