我很新的C++和我使用的libcurl使一個HTTP請求,並取回與響應的內容的字符串。STD字符串問題的libcurl - C++
size_t write_to_string(void *ptr, size_t size, size_t count, void *stream) {
((std::string*)stream)->append((char*)ptr, 0, size*count);
return size*count;
}
int main(void) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.browsarity.com/");
std::string response;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
// The "response" variable should now contain the contents of the HTTP response
}
return 0;
}
運行上面的代碼(與VS2005)後,我得到這個錯誤:
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" ([email protected][email protected]@@[email protected])
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" ([email protected][email protected]@@[email protected])
1>libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" ([email protected]@@[email protected])
它看起來像它的一些庫問題,我嘗試添加「MSVCRTD.LIB」我仍然得到上面的錯誤與其他新錯誤。
答案: 我將運行時間庫從多線程(/ MT)更改爲多線程調試DLL(/ MDd)。
如何鏈接我的dbug構建?使用visual studio 2005 .. – shaimagz 2010-03-07 05:39:28
如何將std :: string更改爲char *? – shaimagz 2010-03-07 05:53:07
不知道爲什麼std :: string不應該是公共接口的一部分。另一種選擇是char *,它有自己的問題。 – Ben 2010-03-07 05:55:03