Използвам кода по-долу в два различни независими проекта.
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html"))
.then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.bing.com/"));
// Build request URI and start the request.
uri_builder builder(U("/search"));
builder.append_query(U("q"), U("cpprestsdk github"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
})
;
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception& e)
{
printf("Error exception:%s\n", e.what());
}
Проект 1: е по-голям с други неща. Проект 2: единият съдържа само кода по-долу
когато компилирам и стартирам Project 2, не възникват грешки и кодът работи перфектно, но ако компилирам Project 1, той се компилира без грешки, но по време на изпълнение възниква грешка в uri_builder builder(U("/search"));
, която казва:
Изключение, хвърлено при 0x00007FF643034EE7 в Sgimri_TC2_V2.exe: 0xC0000005: Насилие при достъп за четене на позиция 0x0000000000000000. (Преведох това от немски на английски)
тази грешка възниква в xstring тук:
public:
basic_string(const basic_string& _Right)
: _Mypair(_One_then_variadic_args_t{}, _Alty_traits::select_on_container_copy_construction(_Right._Getal())) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_Construct_lv_contents(_Right);
_Proxy._Release();
}
конкретно грешката възниква в този ред _Construct_lv_contents(_Right);
Това е свързано с конструктора на uri_builder
, където някои компоненти са NULL. Нещо подобно се случи тук, но не знам как да реши го.
Някой има ли решение, намек или съвет, който да ми помогне? Би било чудесно!
Благодаря.