what "problem" does it say it's having? Copy the error log and post it here so that we can see it.
zandiago
Nearly a Posting Maven
2,480 posts since Jun 2007
Reputation Points: 129
Solved Threads: 26
>SRL 3.81 to SRL 4.exe has encountered a problem and needs to close.
Classic runtime error. It means you're probably overrunning a buffer somewhere. Run your program in debug mode and step through it until you hit the error. That'll give you a good idea of where the error is being manifested, and you can trace it back the cause from there.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>i dont get error when i run it in debug mode...
Then sprinkle debug messages everywhere and run it in release mode. Are you really this helpless or are you just trying to get us to do your troubleshooting for you?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
> If someone knows why this is happening, that would be great.
I've got two pretty good ideas where the problem is (ok, 3 actually).
> while (getline(fin, line[counter]))
What stops this over stepping the array?
> for(counter=0; counter<5000; counter++)
Why 5000 and not the number of lines you read?.
Since this is the same variable, why did you even bother with counting them?
> for(index=0; index<11; index++)
How many entries are there in strtofind ?
Come to think of it, why do you even bother storing the whole file in memory at all. "Read a line, do the subs, write out the line" would work just as well in a loop.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
> >What stops this over stepping the array?
> huh?
What happens if the file has more than 5000 lines?
> but im trying to use new and delete for the array of line
Consider using a std::vector then, and save yourself a lot of confusion.
Besides, you should concentrate on getting this one to work rather than trying to rewrite it whilst it still has bugs.
> well, i think that if you open a ofstream, everything else in the file is deleted, am i correct?
Personally, I would create a temp file, then only replace the old file when I know the new file is created successfully.
If for some reason your program crashed soon after the fout.open(File); you'd lose the lot.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
> how do i use vectors?
std::vector<std::string> lines;
std::string aLine;
while ( getline(fin, aLine) ) lines.push_back(aLine);
You can then use lines.size() and a for loop to iterate over the vector, exactly like you would do using an array.
> temp file? i would run into the same problem, wouldn't i?
No.
You read from the input file, and write to the temp file.
You then close both files.
You then delete the original input file.
You then rename the temp file back to the original file.
The only danger is that you MAY end up with all your data in the temp file, but you will never outright lose all your data.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
http://www.sgi.com/tech/stl/
Probably not what a noob needs, but it's late and I have other stuff to do.
If your book doesn't explain the STL in any way, you need another book.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953