错误:"ios_base"尚未声明
error: 'ios_base' has not been declared
我正在使用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::
。
相关文章:
- #ifdef和未声明的标识符
- 未声明的标识符编译暗黑破坏神 2 程序"muleview"
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 在气泡排序程序中未声明错误功能
- 我在范围内未声明的错误类有问题
- 使用未声明的标识符"sqrt"?
- 我包含了<winuser.h>,但编译器在MonitorFromWindow上抛出"未声明"
- 对类 (C++) 中的私有变量使用未声明的标识符
- 我的代码中有错误,未声明的标识符
- 未定义的标识符/未声明
- 错误:在 C++ 'std'使用未声明的标识符
- 在编译器之前检测未声明的标识符
- 使用未声明的标识符'temp'
- 使用未声明的标识符"yylex"和"yyin"?
- 使用"class"关键字,后跟未声明的标识符
- 未声明的标识符错误,但变量定义正确 (?)
- C2065 'cout':未声明的标识符
- 在此范围内未声明错误"Clreol"
- C++模板模板参数中未声明的标识符