| stevemaples (9) | |||
|
The following code works if i leave out the lineIn.insert(i,"\n"); line. when i put that line in, the program goes into an infinite loop. I am trying to read a line of text from a text file and insert a newline where str1 is found. It acts like a internal pointer is being reset to the first part of the string when i use the insert function.
| |||
|
|
|||
| ne555 (4383) | |
|
Do a desk test. You've got an infinite loop because you always find the string. | |
|
|
|
| stevemaples (9) | |
|
something else i discovered, the lineIn string does get str1 inserted into it, but it is always the first string read from the file and it continues to put the str1 into the first string until eof. what is a desk test? | |
|
|
|
| ne555 (4383) | |||
|
Go to a desk with pen and paper. Simulate your program (act as the computer) By the way, you should read as
| |||
|
|
|||
| stevemaples (9) | |
|
thank you for your reply. the infinite loop only occurs when i put the lineIn.insert(i,"\n"); line in. | |
|
|
|
| vlad from moscow (3662) | |
|
You always insert the new line character before str1. Then you increase i that again points to str1. So the same value of str1 will be found next time. In fact your code does the following \n\n\n...\nstr1 | |
|
|
|