c++ - Reading to object from .in file -


hello i'm having list of 3 int's spaced 2 white-spaces, , want read them , create object. paste code data strucutre, class , pre/post data. cant find reason error. welcome:

class.h:

class rangle{ private:     int x,y,l,b;      int solution,prec;     rangle(){         x = y = solution = prec = b = l = 0;     }      rangle(int i,int j,int k){         x = i;         y = j;         l = k;         solution = 0; prec=0; b=0;     }      friend ostream& operator << (ostream& out, const rangle& ra){         out << ra.x << " " << ra.y<<" " << ra.l <<endl;         return out;     }      friend istream& operator >>( istream& is, rangle& ra){         >> ra.x;         >> ra.y;         >> ra.l;          return ;     }  }; 

datastructure.h:

template <class t> class list { private:     struct elem     {         t data;         elem* next;     };      elem* first;      void push_back(t data){     elem *n = new elem;     n->data = data;     n->next = null;     if (first == null)     {         first = n;         return ;     }     elem *current;     for(current=first;current->next != null;current=current->next);     current->next = n; } 

main.cpp:

void readdata(list <rangle> &l){     *rangle r;     int n;     ifstream f_in;     ofstream f_out;      f_in.open("ex.in",ios::in);     f_out.open("ex.out",ios::out);      f_in >> n;     for(int i=0;i<13;++i){         f_in >> r;         cout << r;         l.push_back(r);     }      f_in.close();     f_out.close(); }* 

input data:

3 1 2 1 1 3 3 1 1 

output(at printing when reading):

1 2 1 1 3 3 1 1 3 

as can see somehow starts reading 2-nd position , finishes first.

as can see somehow starts reading 2-nd position , finishes first.

that's because extract first value.

in readdata function:

f_in >> n;    //  line extract first value stream.  // loop starts @ second value for(int i=0;i<13;++i){ f_in >> r;     cout << r;     l.push_back(r); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -