Может ли кто-нибудь сказать мне, почему приведенный ниже код кода, который я написал при компиляции, продолжает жаловаться istream_iterator is not a member of std
, пожалуйста, вы можете сказать? Спасибо ребятаC++ 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";
}
Поэтому, пожалуйста, если вы заметили вопрос, дайте мне знать, как я не могу точно сказать, на данный момент, и я полагаю, что я положил в все необходимые библиотеки включают
Привет, спасибо, что решаемые мой problem.but я не могу печатать с для какой-либо причине. Я вставляю файл csv, читаю его и хочу использовать cout s. Почему не работает, можете ли вы сказать? – Lexka
@Lexka Я бы сказал, это потому, что ваш '& operator >>' overload не считается запятыми (','), пока вы читаете CSV-файл. – user35443
Здравствуйте, можете ли вы предложить исправление, пожалуйста? Я изо всех сил пытаюсь это разрешить. Спасибо man – Lexka