gpt4 book ai didi

c++ - 错误 : 'ios_base' has not been declared

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:28:36 26 4
gpt4 key购买 nike

我正在使用 libcurl 下载序列化代码并将其打开,但是,我收到一个错误,看起来 fstream 丢失了,但它包含在内。我环顾四周,但很少发现错误。下面是错误和代码。错过了什么?

编译错误输出

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

代码:

#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);

return numBytes;
}

//function to get coin data and 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 the request, res will get the return code */
CURLcode res = curl_easy_perform(curl);

/* Check for 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 Last Traded Price is = " << document["lasttradeprice"].GetString() << std::endl;
}

/* always cleanup */
curl_easy_cleanup(curl);
}

//timer for URL request. *ADUJST ME AS DESIRED*
usleep(10000000);
}

return 0;
}

//Le Main
int main(void)
{
getData();
}

最佳答案

ios_base 位于命名空间 std 中。在 ios_base 之前添加前缀 std::

关于c++ - 错误 : 'ios_base' has not been declared,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26558184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com