Mam następujący problem: przy próbie kompilacji poniższego kodu
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Dane;
typedef vector<Dane> VECT;
class Dane {
string sel_code;
string art_code;
int quant;
int price;
public:
friend ostream& operator<<(ostream&, const Dane&);
friend istream& operator>>(istream&, const Dane&);
};
ostream& operator<<(ostream& str, const Dane& d)
{
str << d.sel_code << d.art_code << d.quant << d.price;
return str;
}
istream& operator>>(istream& str, const Dane& d)
{
return str >> d.sel_code >> d.art_code >> d.quant >> d.price;
}
int main()
{
VECT vec;
ifstream plik("dane.dat");
istream_iterator<Dane> pocz(plik),kon;
copy(pocz,kon,back_inserter(vec));
cout << "Po wczytaniu:\n";
copy(vec.begin(),vec.end(),ostream_iterator<Dane>(cout," "));
return 0;
}
dostaję komunikat błedu:
Error E2094 : 'operator>>' not implemented in type 'istream' for arguments of type 'string' in function operator >>(istream &,const Dane &)
Czy ktoś może mi wyjaśnić o co chodzi i ewentualnie wskazać gdzie trzeba poprawić kod?
Dodam, że struktura danych w pliku dane.dat ma postać:
string1 string2 int1 int2
(cztery dane w każdej linijce, dwa łańcuchy, dwie liczby całkowite, wszystko rodzielone spacjami)
Podany fragment kodu ma czytać dane z pliku i wpisywać od razu do kolekcji typu vector (później testowo wypisać ją na konsolę).
Używam kompilatora Borlanda.
Z góry dzięki za pomoc
Greg