I wanted to make a "word of the day" program. I found a public domain version of webster's at gutenberg.org, and it was arranged in a simple-to-manage format. Each main word is fully capitalized, so that is a easy marker to start with.
The problem, if I'm right, is that the book is too long (28M), so the flags for ofstream stop working. tellg() stops sending information at a little past 28 million characters, so something is definitely broken in the ofstream class. I end up with an infinite loop in which file.eof(), file.good() and file.bad() won't stop it.
Is there a way to copy a file in blocks of data rather than letter by letter? If so, do you have a suggestion of how to turn those blocks into letters while in-program?
I did, but I decided it would be more fun to try to work out the riddle...
I started this program out of boredom, but it's more of a challenge now; part of the game should be that I can't break the file up ahead of program run time.
Breaking it to pieces during run time is proving to be more difficult than I expected...
I haven't worked with files of such large size before, but I think it's something that I should know how to do.
My first suggestion would be to use the proper type for the function return types. For example what type of variable does tellg() return?
Next if your program is crashing be sure to run it with your debugger. The debugger will tell you exactly where it detects the problem and will allow you to view the variables at the time of the crash.
By the way I don't seem to have any problems reading the file.
FWIW I tried using the gutenberg text file with a small line-reader program I wrote to tokenize text. It had no problem processing the whole file line by line, start to finish.
I didn't try your program on the file but I think you need to examine what your purpose, if any, is in newg, tellg etc.
I suspect you have an indexing problem in allcaps. In short I doubt whether streaming functionality is broken. What you need to do is see if lines displays as expected in each of main and then allcaps.
While I know there is a limit, I suspect the lower value is based on the file system, of course it's limited by disk as well, not ofstream. It should be in the Terabytes on most current OS's.
Just to test your theory, I modified your program, a lot, and it ran fine. Finished in a few seconds if you want to see for your self, its' below.
Since it's only reading a line at a time the only limitation will be disk storage which would have shown up separately as a disk full error or somesuch. If the line is read in as a string then there is no problem with memory.
I am writing the program for a raspberry pi2 which has a 32bit cpu instead of the 64 that most modern computers would have, so I thought that streampos would have a small enough limit for the dictionary's letter count to hit.
NOPE.
The problem is my nested while loop in main does not have an exit, it goes on reading until it finds the next key word and of course the dictionary is not going to end on a keyword so that is where the infinite loop was occurring.
(Smacking forehead)
Thanks for the suggestions, I'll put them into effect.