Output vector to scroll through it with ncurses

Hey there!

I have a vector which holds the contents of a text file and I want to display the vector in a ncurses view, so the user can scroll through the contents. It's for a text editor/viewer.

My current code to view files:
1
2
3
4
5
6
7
8
i = 1;

for (std::vector<string>::const_iterator i = bank.begin(); i != bank.end(); ++i) {
    std::cout << *i;
    std::cout << endl;
}

i =1;


Later I'd like to be able to edit parts with a gap buffer, but I don't know how to realize this.

Any insight would be nice. Thanks in advance! :)
Example using ncurses.
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
#include <ncurses.h>
#include <vector>
#include <string>
int main(int argc, char const *argv[])
{
	initscr();
	noecho();
	cbreak();
	int start_index = 0;
	std::vector<std::string> bank = {"Hello", "There", "World!"};
	while (true) {
		clear();
		int y=0;
		for (std::vector<std::string>::const_iterator 
			i = (bank.begin() + start_index); i != bank.end(); ++i) 
		{
			mvprintw(y++, 0, "%s", i->c_str());
		}

		int key = getch();
		if (key == 'q') {
			break;
		} else if (key == 'k' && start_index > 0) {
			--start_index;
		} else if (key == 'j' && start_index < bank.size()) {
			++start_index;
		}
	}
	endwin();
}
Thank you, Ihatov!
I think there's a problem because I'm reading a file into one big vector string instead of a list of vector strings. Don't know whether this is the right definition for it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
     ifstream input_file(temp);
        
        if (input_file.is_open())
        {
            std::string s((std::istreambuf_iterator<char>(input_file)), std::istreambuf_iterator<char>());
            (void)bank.insert(bank.end(),s);
            
            input_file.close();
            
            temp = "end";
            aw = 1;
            ClearScreen();
            
        } else cout << "Can't open this. Try again or type 'end'." << endl;


What shall I do? I think this will also help me to create my gap buffer.
Topic archived. No new replies allowed.