while(getline(filename,str));
The semicolon at the end of that statement ensures that your loop does nothing useful, apart from reading to the end of the file. You could simplify your code considerably by using a vector, or similar collection, to store the data as you read it, without the need to count the lines in the first place.