c++ - error: 'ios_base' has not been declared -
c++ - error: 'ios_base' has not been declared -
i using libcurl download serialized code , bust open but, error looks fstream missing much included. looked around little on error. below error , code. did miss?
compile error output
g++ -g testgetprice2.cpp -o testgetprice2.o -std=gnu++11 -lcurl testgetprice2.cpp: in function 'int getdata()': testgetprice2.cpp:45:56: error: 'ios_base' has not been declared testgetprice2.cpp:45:72: error: 'ios_base' has not been declared
code:
#include "rapidjson/include/rapidjson/document.h" #include <iostream> #include <fstream> #include <stdio.h> #include <curl/curl.h> #include <unistd.h> #include <unordered_map> #include <string> using namespace rapidjson; struct mydata { std::fstream *file; std::string *str; }; size_t write_data(void *ptr, size_t size, size_t nmemb, mydata *data) { size_t numbytes = size * nmemb; if (data->file) data->file->write((char*)ptr, numbytes); if (data->str) *data->str += std::string((char*)ptr, numbytes); homecoming numbytes; } //function coin info , perform analysis int getdata() { int count = 0; //begin non terminating loop while(true) { count++; curl *curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, curlopt_url, "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=155"); std::fstream file("/home/coinz/cryptsy/myfile.txt", ios_base::out | ios_base::ate); std::string json; mydata data; data.file = &file; data.str = &json; curl_easy_setopt(curl, curlopt_writefunction, &write_data); curl_easy_setopt(curl, curlopt_writedata, &data); /* perform request, res homecoming code */ curlcode res = curl_easy_perform(curl); /* check errors */ if (res != curle_ok) { std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl; } else { file << std::endl; //begin deserialization document document; document.parse(json.c_str()); assert(document.hasmember("lasttradeprice")); assert(document["hello"].isstring()); std::cout << "the lastly traded cost = " << document["lasttradeprice"].getstring() << std::endl; } /* cleanup */ curl_easy_cleanup(curl); } //timer url request. *adujst me desired* usleep(10000000); } homecoming 0; } //le main int main(void) { getdata(); }
ios_base
in namespace std
. add together prefix std::
before ios_base
.
c++ curl libcurl fstream
Comments
Post a Comment