I'm currently making a mock up playlist using queue but I have this problem wherein It won't read up to 5 title from my textfile song directory rather it only reads up to 1 or 3 title depending on the length of the song title. I tried changing the size but it doesn't seems to work.
#include<string>
#include<stdlib.h>
#include<fstream>
using namespace std;
#define size 10
class Playlist{
public:
int rear, front;
string q[size];
string choice;
void Insert();
void Delete();
void Display();
};
void Playlist::Insert()
{
cout<<"Enter a song you want to add in queue"<<endl;
cin.ignore();
getline(cin,choice);
int cnt=0;
int pos;
string array[100];
short loop=0;
string line;
ifstream myfile ("Songs.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
array[loop] = line;
loop++;
}
myfile.close();
}
else cout << "can't open the file";
for(int i=0; i<100; i++)
{
if(array[i]==choice)
{
cnt=1;
pos=i+1;
break;
}
}
if(cnt==0)
{
cout<<"\n Song not Found..!!"<<endl;
}
else
{
if(rear<size)
{
rear++;
q[rear]=choice;
}
if(front==0)
{
front=1;
}
else cout<<"Queue is full"<<endl;
}
}```