0

I saw that there were many topics but I still didnt found somethings that I can get help from..

I am trying to read from a txt file which each line is in this template:

    movie1-2000 1 2 3 4
    movie2-2000 4 3 2 1 
    movie3-2002 6 8 4 9
    movie4-2003 3 3 3 3
    movie5-2004 7 6 5 9

When the 'movie i' is the name of the movie - year that came out, and the numbers at the right are like features that describes the movie. 
The thing is that I dont know how many features will be, it can be 4 numbers(as its shows at the examples), more, or less. 
I need to split it to string(movie name), int(year), and vector<double> with features values.

      int counter = 0;
      fstream file;
      file.open ("example.txt",std::ios::in);
      if (file.is_open()){
        string line;
        string name;
        double num;
        int year = 0;
        vector<double> vec;
        while (getline (file,line,'-')){
          name = line;
          while (file >> num)
          {
            if (counter == 0){
              year ==(int) num; 
            }
            else{
             //need to implement vec 
            }
            counter++;
          }
         counter = 0;
        }

The problem is that I dont know how to implement the vec, because its unknown size, and I dont know how to dynamicly get the size of the features line. Also, after one line of reading the file its exit the big while loop from some reason.. Thank you!

OmerC
  • 19
  • 3

0 Answers0