Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;istream_迭代器不是std的成员_C++_Istream Iterator - Fatal编程技术网

C++ C++;istream_迭代器不是std的成员

C++ C++;istream_迭代器不是std的成员,c++,istream-iterator,C++,Istream Iterator,有人能告诉我为什么我在编译时编写的下面的代码总是抱怨istream_iterator不是std的成员吗? 谢谢各位 #include <cstdlib> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <vector> #include <fstream> //#include<s

有人能告诉我为什么我在编译时编写的下面的代码总是抱怨istream_iterator不是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::ctype{
字段_reader():std::ctype(get_table()){}
静态std::ctype_base::mask const*get_table(){
静态std::vector
rc(表大小,std::ctype_base::mask());
rc[';']=std::ctype_base::space;
返回&rc[0];
}
};
结构螺柱{
双交通工具;
双财政年度;
双车型;
双制造商;
双倍分数;
friend std::istream&operator>>(std::istream&is、螺柱与s){
返回值为>>s.VehicleID>>s.FinancialYear>>s.VehicleType>>s.Manufacturer>>s.ConditionScore;
}

//我们还将添加一个操作符错误消息听起来可能有点误导,但这是编译器能说的最好的话。
std::istream\u迭代器
头文件中声明,这就是导致问题的原因

只需将此添加到您的附件中即可

#include <iterator>
#包括

你好,谢谢你解决了我的问题。但由于某种原因,我无法打印s。我插入了一个csv文件,读入它并想打印s。你能告诉我为什么不工作吗?@Lexka我想说这是因为你的
&操作符>
重载不能用逗号计算(
),当您正在读取CSV文件时。您好,您能建议更正吗?我正在努力解决此问题。首先,我会尝试读取一个不包含分隔值的逗号的文件。然后,在使用CSV时,您可以在字段中读取,跳过逗号,然后再次在字段中读取,或者只是创建一个虚拟的
char
variable用于阅读逗号。@Lexka提出新问题,而不是用不相关的问题混淆完美的问题。