I'd like to apologize for posting a homework problem. I really try to figure these things out by myself, but I've been at this little problem for a few hours now and it is past being a productive learning experience.
I am trying to read an input file and populate two arrays. The input file is of a cd collection like this:
I need to load the file using a function and populate two parallel arrays, so that I can sort and manipulate them later. I'm pretty sure the problem is in my while loop. I have tried changing the parameter to !cdList.eof(). I have also tried using getline(cdList, cdTitle[incr]) to populate the arrays. I get unhandled exception errors and sometimes the program prompts me for the input file as expected, but will then either do nothing, crash, error, or display (). I also have tried having the input file in both debug folders, i hope thats where its supposed to be.
I think my problem is an array out of bounds because of improperly using an eof controlled while loop, but I haven't been able to find an applicable example in the forum or anywhere else online. Any help is appreciated, thank you!
I hadn't tried it exactly that way yet, but it makes sense. I implemented your code and put the error statement first and the function returns -1 and I get my "Error loading file." message. If i comment out the error protection, incr stays at 0 because it will display" () "and end the program.
I'm not sure what I am doing wrong when it comes to loading the input file. There are two debug folders in the project file and I have tried putting it in both of them, and I know I am typing the correct filename with the correct extension. There must be something else I am overlooking. I am using visual studio 2010. Is there a way to check which directory it is looking in? Do i need to import the file into the project somehow? I had tried adding it as a source file prior to posting, but it change anything then.