Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: How to guide not compiling on VS2010

$
0
0
Nested lambdas.

VS 2010 has trouble with nested lambdas, and so the fix is to unnest the lambda. The following at least compiles, but I haven't tried running it.

Niklas
// Creates an HTTP request and prints part of its response stream.
pplx::task<void> HTTPStreamingAsync()
{
    http_client client(L"http://www.fourthcoffee.com");

    streams::container_buffer<std::string> inStringBuffer;

    auto nested = 
        [inStringBuffer](size_t)
        {
            const std::string &text = inStringBuffer.collection();

            // For demonstration, convert the response text to a wide string.
            std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf16conv;
            std::wostringstream ss;
            ss << utf16conv.from_bytes(text.c_str()) << std::endl;
            std::wcout << ss.str();
        };

    return client.request(methods::GET).then(
        [inStringBuffer, nested](http_response response) -> pplx::task<void>
        {
            if(response.status_code() != status_codes::OK)
            {
                // Handle error cases... 
                return pplx::task_from_result();
            }

            // Perform actions here reading from the response stream... 
            // In this example, we print the first 15 characters of the 
            // response to the console.
            streams::istream bodyStream = response.body();
            return bodyStream.read(inStringBuffer, 15).then(nested);
        });
}

Viewing all articles
Browse latest Browse all 4845


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>