Don't double-post. It is frowned upon. The same applies to quadruple posting, but with more intensity. There's an edit function for a reason.
The same error will occur in any compiler post-2000. VC++ 6.0 follows only part of the standard. If you care at all about the quality of your code, you'll fix it so at least gcc can compile it (practically a requirement for any C++ program that doesn't use any special libraries).
Those aren't bugs. They are issues.
You can't write a proper text editor using streams. You need to use some console library like ncurses.
The second item comes from your misunderstanding of the behavior of std::cin.
The third one is probably a logic error easily fixed.
General style: Prefer the style
over the style
This makes the code easier to edit.
And on that same line, avoid this:
1 2 3 4 5 6 7 8
|
//Comment
statement;
//Comment
statement;
//Comment
statement;
//Comment
statement;
|
Instead, do this:
1 2 3 4 5 6 7 8 9 10 11 12
|
/*
Comment.
Comment.
Comment.
Comment.
Comment.
*/
statement;
statement;
statement;
statement;
statement;
|
Needless to say, hyperverbose comments is not a good thing.
1. main should return an int, not void.
2. Line 40: The condition will always be false. You examine the condition inside the loop at line 60 and finish if it's true.
3. Lines 42-44: Condense these into a single string.
4. Line 62: Whenever possible (i.e. always), put if and else statements in lines of their own to increase readability.
5. Line 64: Just don't.
6. Line 75: Again.
7. Line 78: std::cin will stop reading at the first whitespace it finds. This is the cause of issue 2. You can use getline, as you have on other places.
8. Lines 80-84: Read this:
http://www.cplusplus.com/reference/string/string/find.html
9. Line 85: else statements aren't mandatory. If you have nothing to do in them, just leave them out.
10. Line 89: Instead of setting a flag, why not just add the extension in the previous if?
11. Lines 97 and 98: See comment 3.
12. open_file(): A significant portion of this function is duplicate code. You might want to move it to main().
13. Loop starting on line 142: What happens if the file has more that 30 lines? I'll tell you what happens. A fence post error happens, that's what.
14. Lines 152-154: See comment 3.
15. Line 166: Use the std::ios::app flag to open the file. Also, comment line 173. This somewhat fixes issue 3.
16. Line 168: Just awful.
17. Line 170: Here is the scope error. Also, completely irrelevant comment.
18. Line 176: Don't do more string comparisons than are necessary. They aren't cheap. Replace the condition with a 1 and put a break in the else block.
19. cannot_open_file(): All of its overloads are essencially the same function. You can do the same with a single function using templates.
That's all for now.