How do advanced text editors like vim,nano... work???

How do advanced text editors like vim or nano work???
I'm trying to make myself a text editor as a project....and it'll not be a replacement for those spelled above.It's just a fun project.

I'm trying to understand the concepts behind these type of programs.Any weblinks or useful resources on the web will be acknowledged,Sir!!!

As an example,heres some of my code:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

#ifndef FILE_READER_HPP_INCLUDED
#define FILE_READER_HPP_INCLUDED

#define NDEBUG

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>

class Reader
{
private:
    std::string filename;
protected:
    std::fstream fio;
    std::string input,output;
public:
    Reader();
    Reader(std::string &a);
    ~Reader();
    void getfilename(std::string &a);
    //std::string Input();
    void Input();
    void Output();
};

Reader :: Reader()
{
    filename = " ";
    input = " ";
    output = " ";
}

Reader :: Reader(std::string &a)
{
    filename = a;
    input = " ";
    output = " ";
}

Reader :: ~Reader() {}

void Reader :: getfilename(std::string &a)
{
    filename = a;
}

/* 
string  Reader :: Input()
{
     string temp;
     fio.open(filename.c_str(),ios::in|ios::binary);
     
     if(fio.fail())
         throw "Unable to open file !!!\n";
     
     else 
     {
         while(!fio.eof())
         {
             fio.getline(input,256,"/n");
             temp +=input;
         }
     }
     fio.close();
     return temp;
}
*/

void Reader :: Input()
{
    fio.open(filename.c_str(),std::ios::in|std::ios::binary);
     
     if(fio.fail())
         throw "Unable to open file !!!\n";
     
     else 
     {
         while(!fio.eof())
         {
             assert(std::getline(fio,input)) ;
	     std::cout<<input<<std::endl;
         }
     }
     fio.close();
}

void Reader :: Output()
{
    fio.open(filename.c_str(),std::ios::out|std::ios::binary);
    
    if(fio.fail())
        throw "Unable to open file !!!\n";
    
    else 
    {
        while(!fio.eof())
        {
	    assert(std::getline(std::cin,output,'\n'));
	    std::cin.clear();
	    assert(fio<<output<<std::endl);
        }
    }
    fio.close();
}

#endif

//-----------------------------------------------------------------------------


#include <iostream>
#include <string>
#include "File_Reader.hpp"

using namespace std;

int main()
{
    try
    {
        Reader *r = new Reader;
        string s;
    cout<<"Enter the file name to open....\n";
    cin>>s;
    r->getfilename(s);
    int ch = 0;
    while(1)
    {
       cout<<"1: Write to the file \n"
           <<"2: Read from the file \n"
           <<"3: Exit from the program \n";
       cout<<"Enter choice .... \n";
       cin>>ch;
       switch(ch)
       {
          case 1: 
             cin.clear();
             r->Output();
             break;
          case 2:
             r->Input();
             break;
          case 3:
             cout<<"Thank you !!!\n";
             return 0;
             break;
          default: 
             cout<<"Wrong Choice !!!\n";
             break;
        }
    }
   
    delete r;
    }
    catch(string &e) { cout<<e<<endl; }
    
    return 0;
}


This is the code I've written so far.
Pls reply with suggestions and some good articles....
Very thnx to all for reading :D
Topic archived. No new replies allowed.