0

I have a struct vector "array" that's looks like

struct competitor
{
    vector<string> name;
    vector<int> points;
};

and I have a file which contains names and 10 pieces of result point I would like to read in, but I can't append to vector. I can't read it

int i = 0;
string tmp;

while(!x.eof())
{
   getline(x, tmp, '\t');
   t[i].name.push_back(tmp);
   // tmp >> t[i].name;
   cout << tmp << endl;

   for(int i = 0; i < 11; i++)
   {
       x >> tmp;
       t[i].pontok.push_back(tmp);
   }
   i++;
}
  • 2
    [`while (!eof())` is wrong.](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – chris Apr 14 '14 at 14:33
  • 1
    `for(int i=0; i<11;i++)` that means 11 iterations, not 10. It would be 10 if you start from 1. – Marius Bancila Apr 14 '14 at 14:34
  • Attempt tracing your code, in other words execute it "on the paper" step be step in order to debug it. Be very careful on loop times, eof checks, and even variable correct initializations. Fix each step you find buggy, till the code is bug free. – Nick L. Apr 14 '14 at 14:41
  • But i don't know that how long is the file, but i know that there are name and 10 points – user3532307 Apr 14 '14 at 15:24
  • @MariusBancila: No, it's 10. It would be 11 if it said i<=11. – George T Apr 14 '14 at 15:32
  • yes but i take off the names befor the program step in for. the files separate by tab and a "split tab" the names and after remaind the numbers – user3532307 Apr 14 '14 at 15:38
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 . Count it yourself. There's eleven of it... – zoska Apr 14 '14 at 15:42
  • `tmp` is a string, but you want to push it back to int vector. Why? – zoska Apr 14 '14 at 15:43
  • Also there is a member naming mismatch in your code : pointspontok. Please, check your code once more. – zoska Apr 14 '14 at 15:44
  • it's unified in my file, but i have a problem to APPEND!!! Code blocks has a problem that no matching fuction for call to 'std::vector >::push_... – user3532307 Apr 14 '14 at 15:57

0 Answers0