0

[c++] stuck, help please! out_of_range error

when i run this code, it gives me out if range error and closes the command prompt. i read that this has something to do with the forever looping. what can i do here? on a similar note, how can i find a string in a txt file and replace it? this code is for the same purpose. If you've any idea in how should i approach this, please lemme know. PS: Just ignore the stuff in /* */. that's just something i tried. please and thank you for your help. https://code.sololearn.com/c94p8U5Wxcj5/?ref=app

10th Jun 2017, 8:10 PM
anonymous
2 Réponses
0
Almost 100 lines of code, too much to read, and too little in the way of comments. Also, use more meaningful naming for variables and functions. That said, the brute force way of finding and replacing text in files is to read the file into memory, look for the string to be replaced with, replace it with the string to replace with, and write the whole thing back to the file. Professional text editors such as sed, awk, Vi, Emacs, and the whole lot of others sure use some decent data structure and algorithm to make things simpler and quicker. One such recent data structure is rope, employed by the Yi-editor, the Haskell scriptable editor. I think someone is writing Emacs in Rust and is on to some cool data structures as well.
11th Jun 2017, 1:45 AM
Venkatesh Pitta
Venkatesh Pitta - avatar
11th Jun 2017, 3:15 AM
Bibek Ghimire
Bibek Ghimire - avatar