C++ istream_iterator 不是 std 的成员

标签 c++ istream-iterator

谁能告诉我为什么我在编译时写的下面这段代码一直在提示 istream_iterator is not a member of std 请你告诉我吗? 谢谢大家

#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <fstream>
//#include<sstream>

struct field_reader: std::ctype<char> {

    field_reader(): std::ctype<char>(get_table()) {}

    static std::ctype_base::mask const* get_table() {
        static std::vector<std::ctype_base::mask>
            rc(table_size, std::ctype_base::mask());

        rc[';'] = std::ctype_base::space;
        return &rc[0];
    }
};


struct Stud{
    double VehicleID;
    double FinancialYear;
    double VehicleType;
    double Manufacturer;
    double ConditionScore;


    friend std::istream &operator>>(std::istream &is, Stud &s) {
        return is >> s.VehicleID >> s.FinancialYear >> s.VehicleType >>      s.Manufacturer >> s.ConditionScore;
    }

    // we'll also add an operator<< to support printing these out:
    friend std::ostream &operator<<(std::ostream &os, Stud const &s) {
        return os << s.VehicleID  << "\t"
                  << s.FinancialYear << "\t"
                  << s.VehicleType    << "\t"
                  << s.Manufacturer   << "\t"
                  << s.ConditionScore;
    }
};

int main(){
// Open the file:
std::ifstream in("VehicleData_cs2v_1.csv");

// Use the ctype facet we defined above to classify `;` as white-space:
in.imbue(std::locale(std::locale(), new field_reader));

// read all the data into the vector:
std::vector<Stud> studs{(std::istream_iterator<Stud>(in)),
 std::istream_iterator<Stud>()};

// show what we read:
for (auto s : studs)
    std::cout << s << "\n";
}

所以,如果您发现问题,请告诉我,因为我目前还不能完全确定,我相信我已经放入了所有必要的包含库

最佳答案

错误消息可能听起来有点误导,但这是编译器可以说的最好的东西。 std::istream_iterator<iterator> 中声明头文件,这就是导致您的问题的原因。

只需将此添加到您的包含中

#include <iterator>

关于C++ istream_iterator 不是 std 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30694570/

相关文章:

c++ - 如果我想使用 std::shared_ptr,要包含哪个 header ?

c++ - 如何连接两个程序(c++、qt)

c++ - 在混合 C++ 中捕获标准异常和系统异常

c++ - 非生成的特殊成员函数与删除的特殊成员函数

c++ - 绘制从二值图像中检索到的轮廓

c++ - 使用 istream_iterator 并从标准输入或文件中读取

c++ - std::istream_iterator<double> 成员变量在递增时失败

c++ - istream_iterator<T> 表示 std::endl