繁体   English   中英

C ++ istream_iterator不是std的成员

[英]C++ istream_iterator is not a member of std

任何人都可以告诉我为什么编译时我写的下面的代码一直抱怨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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM