2017-01-07 2 views
1

Ich mache einige Code, wo ich die Ausgabe in eine Datei umleiten, aber ich bekomme Fehler mit dem Stream, ostream, streambuf(). Er sagt, dassC++ - Fehler beim Speichern in Datei mit Stream

- "fstream" mehrdeutig ist

- "Ostream" ist mehrdeutig

-Klasse "std :: basic_ostream>" hat kein Mitglied "streambuf"

-Klasse „std :: shared_ptr "hat kein Mitglied" schließen "

Ich suche bereits nach Includes, installierte die neueste Version der Casablanca Rest API, ... und ich bekomme immer noch diese Erros .. seine fehlenden einige enthalten? Hier

ist der Code

#include <sstream> 
#include <iostream> 
#include <fstream> 
#include <cpprest/http_client.h> 
#include <cpprest/filestream.h> 
#include <cpprest/http_listener.h>    // HTTP server 
#include <cpprest/json.h>      // JSON library 
#include <cpprest/uri.h>      // URI library 
#include <cpprest/ws_client.h>     // WebSocket client 
#include <cpprest/containerstream.h>   // Async streams backed by STL containers 
#include <cpprest/interopstream.h>    // Bridges for integrating Async streams with STL and WinRT streams 
#include <cpprest/rawptrstream.h>    // Async streams backed by raw pointer to memory 
#include <cpprest/producerconsumerstream.h>  // Async streams for producer consumer scenarios 


using namespace utility;     // Common utilities like string conversions 
using namespace web;      // Common features like URIs. 
using namespace web::http;     // Common HTTP functionality 
using namespace web::http::client;   // HTTP client features 
using namespace concurrency::streams;  // Asynchronous streams 

using namespace web::http::experimental::listener;   // HTTP server 
using namespace web::experimental::web_sockets::client;  // WebSockets client 
using namespace web::json; 



//Method 

    auto fileStream = std::make_shared<std::ostream>(); 

    // Open stream to output file. 
    pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile) //Error here on the fstrea and ostream 
    { 
     *fileStream = outFile; 

     // Create http_client to send the request. 
     http_client client(U("http://localhost:53213")); 

     // 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()); //Error here on streambuf 
    }) 

     // Close the file stream. 
     .then([=](size_t) 
    { 
     return fileStream.close(); //Error on 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

Haben Sie versucht, die 'std' Präfix wie 'std :: fstream'? –

+0

ja. Wenn ich hinzufügen std :: fstream hier: fstream :: open_ostream (U ("results.html")), dann ([=] (ostream outFile), erhalte ich die folgende Fehlermeldung:. \t Klasse „std :: basic_fstream > "hat kein Mitglied" open_ostream " – Tazz

+1

@Tazz Es hat kein' open_ostream' Mitglied. Hören Sie auf zu raten und lesen Sie einige Dokumentationen. Ein gutes Buch wäre wahrscheinlich auch eine gute Idee. – molbdnilo

Antwort

1

-"fstream" is ambiguous

-"ostream" is ambiguous

-class "std::basic_ostream>" has no member "streambuf"

Du clashing std:: und Casablancas concurrency::streams Namensräume, entweder sicherzustellen, dass sie nie mit using in einer Datei oder verwenden concurrency::streams explizit

-class "std::shared_ptr" has no member "close"

gezogen

aber es funktioniert nicht! verwenden -> auf Ihrem fileStream


EDIT: Ich denke, Ihr Code ist nichts anderes als leicht modifizierte Version des offiziellen sample, können Sie einfach überprüfen, dass Sie es richtig

Verwandte Themen