Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'm, hoping that someone can help me out with a problem i'm having. I'm making a program for management of small personal libraries. i recently ran into a bug while loading the program where it had to close. I'm not sure what exactly is causing the error so i was hoping someone could help me find and solve it. I think something in the function i'm using to load the library file (a text file) is causing it so here's the source for the function:
void loadLib()
{
//this function loads the library file into the global loadedLibrary array
ifstream openLibFile("library.txt");
int cellColumn, cellRow;openLibFile.open();
if (! openLibFile)
{
cout << "\a !!Program Error!!" << endl;
cout << "Error Code: 426" << endl;
cout << "The program cannot find the library file!" << endl;
cout << "Please make sure the library file is in the application directory!" << endl;
cout << "If you require further assistance please contact the program" << endl;
cout << "developer at " << endl;
cout << "with the title \'Drake Error \', please include the error code above" << endl;
cout << "and a description of what you were doing before you received the error." << endl;
cout << "The program will start without a library file." << endl;
cout << "Press enter to continue.." << endl;
cin.get();
}
else
{
cout << "Loading library....." << endl;
while (! openLibFile.eof())
{
if (cellRow = 4)
{
getline(openLibFile, loadedLibrary[cellColumn][cellRow]);
lastColumn++;
cellColumn++;
cellRow = 0;
}
else
{
getline(openLibFile, loadedLibrary[cellColumn][cellRow++]);
; }
}
openLibFile.close();
}
}
Thanks in advance for your help
If you have any questions regarding this please ask.

You never told us the error you're getting.
I'm not sure if your complier will allow it (I don't think it's suppose to), but you have a semicolon by itself on line 38.
35 else
36 {
37 getline(openLibFile, loadedLibrary[cellColumn][cellRow++]);
38 ; }
39 }
40 openLibFile.close();

The error i'm getting is windows telling me that the program encountered an error and needs to close. unfortunately that's about as detailed as it gets.
Removing the semi-colon seemed to fix that problem. Thanks for your help, i've got a new problem though, now its not finding the library file and is displaying the library not found error message, when the library file is in the directory with it.

nevermind, fixed that problem, now it's quitting while loading the library file again. same error message as before.

In that case, my guess would be that your globally declared array "loadedLibrary[][]" is too small for the amount of data used.

hmm, could be, but i don't think so, the library.txt file i'm loading only has information for about 20 books, the array is 500 indices long. could it be that it's too long?

Alright, alright. I'll take a closer look. (Read: Run it though my compiler.)
1: Neither cellColumn nor cellRow are initialized to 0.
2: I'm not sure of the version of fstream you're using, but mine forces me to declare the file to use in the open() statement. IE:
ifstream openLibFile;
openLibFile.open("library.txt");3: if (cellRow = 4) should be if (cellRow == 4)
4: I'm not sure you can get away with two dimensional string arrays. You might need to make it a one dimensional array.
That's it for now.

Update to #4: It's not that you can can't use two dimensional string arrays. The problem is the string class overrides the [] operator. So, you'll probably end up with something that looks like this:
loadedLibrary[cellColumn][cellRow][0] = ...

So the string class is overriding essentially what is the
address of the cell? I'm not sure i completely understand

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |