Text Editor console app

hi i am trying to make a text editor to run in a console window,
i have a bit of it working (open files,create and write to new files)
but i dont know how to move the curser position around can
somebody help please. i dont want to have to use os dependant stuff if i dont have to.


i am on windows xp with dev c++;

here is what i have so far;
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
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;

int openfile();
int newfile();

    string   fileopen;
    string   createfile;
    string   text;
    ofstream outfile;
    ifstream infile;
    
int main()
{
    char     options;
    
        
    do
    {
    system("cls");
    cout <<"\t\t-------------------------------------" <<endl;
    cout <<"\t\t| [o]pen file | [N]ew file | [e]xit |" <<endl;
    cout <<"\t\t-------------------------------------" <<endl;
    options =getch();
    
    switch(options)
    {
                   case 'o':
                        {
                            openfile();
                        }
                   break;
                   case 'n':
                        {
                            newfile();
                        }
                   break;
    }
    
    
    }
    while(options != 'e');
    
    return 0;
}

int openfile()
{
    int  i;
    char file;
        
    system("cls");
    cout <<"\t\t-------------------------------------" <<endl;
    cout <<"\t\t|             OPEN FILE             |" <<endl;
    cout <<"\t\t-------------------------------------" <<endl;  
    cout <<"\t\t|Open file| "; getline(cin,fileopen);
    cout <<"\t\t-----------" <<endl;
    
    if(! infile)
    {
         cout <<"error reading file..." <<endl;
         cin.ignore(256,'\n');
         return -1;
    }
    
    infile.open((fileopen).c_str());
    
    while(! infile.eof())
    {
            getline(infile,text);
            cout << text <<endl;
    }            
    infile.close();
    cin.ignore(256,'\n');
    fileopen.empty();
}
    

int newfile()
{
    
    system("cls");
    cout <<"\t\t-------------------------------------" <<endl;
    cout <<"\t\t|              NEW FILE             |" <<endl;
    cout <<"\t\t-------------------------------------" <<endl;  
    cout <<"\t\t|New File| "; getline(cin,createfile);
    cout <<"\t\t----------" <<endl;
    
       
    getline(cin,text,'\2');
       
    if(! outfile)
    {
         cout <<"error writing to file" <<endl;
         return -1;
    }
    outfile.open((createfile+".txt").c_str());
    outfile << text <<endl;
    outfile.close();
    
}
Google ncurses or PDcurses. They are libraries for console input/output
is there any other way because the last time i looked at pdcurses i couldnt
understand it all
If you don't use *curses, you'll have to deal with system-dependent functions.
If you're using Windows, read these:
http://msdn.microsoft.com/en-us/library/ms686971(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms682087(VS.85).aspx
Why do people assume that writing a CUI is simpler than writing a GUI?

See http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

To compile with PDCurses make sure you link with the pdcurses library. For example, with MinGW I type:

g++ MyConsoleApp.cpp -lpdcurses

Hope this helps.
i will use curses thanks for help.
also i just prefare CUI to GUI :)
Topic archived. No new replies allowed.