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.
line 33: Do not loop on (! stream.eof()) or (stream.good()). This does not work the way you expect. The eof bit is set true only after you make a read attempt on the file. This means after you read the last record of the file, eof is still false. Your attempt to read past the last record sets eof, but you're not checking it there. You proceed as if you had read a good record. This will result in reading an extra (bad) record. The correct way to deal with this is to put the >> (or getline) operation as the condition in the while statement.
1 2 3
while (stream >> var) // or while (getline(stream,var))
{ // Good operation
}
Line 41: If you fail to open the file, you fall through and search the empty array.
Line 43: You're looping through the entire array, most of which are empty strings. You read only loop entries.
use <cstdlib> ... the one you used is for C programs. The difference won't matter until it does, but it can create issues in large projects due to namespaces.
consider using constexpr not #define. #defines are largely bad practice, with a few exceptions (include guards, debug macros, project settings (eg ifdef unix pull in unitstd ifdef windows pull in windows.h sorts of things) and the like.
it would be a little better to read the file apart from inserting. What if you wanted to later insert from typing it in? Its more flexible to split the two things, and easier to debug. If you do this, you can debug your file reader first, then do the insert and debug it knowing the file is correct. If you mix them together, you debug 2 things at once.
ok, so does the new fstream function pull the correct data in? Insert will never work until you have the data it needs. Post the new code will help us.
So here it is the the reading from file works and the arrays works
I'm still not sure how the queue works I added the output of contents in file to show that it works. Now I'm not sure how will the insert works and I'm guessing if it has something to do with size or the array.
@seeplus Thank you so much and the others who helped I'll try to study the constexpr since its new to me. Btw, I fixed the Insert function again by deleting the %maxsize because if it reaches the max size it will loop infinitely.
I also created a new account since my account got reported :V