I have a project that is like an IPOD playlist . Im having trouble reading my data in a struct array without using vectors. My BF says my professor is wrong for making us not use vectors, but that is the rule. Do you guys have any suggestions? My code is below.. my professor said I was close but its still not compiling? Thanks for any help 🙂
Struct Songs{
string title;
string artist;
int mem; //size of file in MBs
}song[20]; //up to 20 possible songs
int main
{
song * pointer = new song;
int num = 0;
ifstream fin;
fin.open("input.txt")
while (fin.good())
{
getline(fin, *pointer[num].title;
if (*pointer[num].title.empty()) //to skip blank lines
continue;
getline(fin, *pointer[num].artist;
fin >> *pointer[num].mem.get(); //get to avoid whitespace/enter
num++;
}
for (int i = 0; i<num;i++) // my test to see if it reads in properly
{
cout << *pointer[num].title << endl;
cout << *pointer[num].artist << endl;
cout << *pointer[num].mem << endl;
}
fin.close();
delete pointer [] ;
return 0;
}
Maybe he wants you to use a queue instead? As the songs could be ‘queued’ in a playlist that may be a more befitting data structure?