我很新的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