C ++ - Wait for user input, but type the following line

So, I am creating a GUI with ascci, I would like to wait for user input, but print the last line of the ascci border. At this point, it will wait for user input, and then print the last ascci border line. Is there any way to fix this?

An example of what I want:

Login screen

====================================================== Welcome to Bank Beta 0.1 ------------------------ (1)Login (2)Create Account USER INPUT HERE ====================================================== 

An example of what I get:

 ====================================================== Welcome to Bank Beta 0.1 ------------------------ (1)Login (2)Create Account USER INPUT HERE 

Here is my code:

 void login () { cout << "======================================================" << endl << "\t\tWelcome to Bank Beta 0.1" << endl << "\t\t------------------------" << endl << endl << "\t\t (1)Login" << endl << "\t\t (2)Create Account" << endl << endl; } int main() { int loginChoice; login(); cin >> loginChoice; cout << "======================================================" << endl; _getch(); } 
+6
source share
1 answer

Since you are working with a console GUI, I suggest using some kind of cursor movement function. It will also save you a lot of time aligning “objects”.

Here is the code that you will need to move the cursor for win and unix

 #ifdef _WIN32 #include <windows.h> void gotoxy(int x, int y) { COORD p = { x, y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p); } #else #include <unistd.h> #include <term.h> void gotoxy(int x, int y) { int err; if (!cur_term) if (setupterm(NULL, STDOUT_FILENO, &err) == ERR) return; putp(tparm(tigetstr("cup"), y, x, 0, 0, 0, 0, 0, 0, 0)); } #endif 

You can remove any of them if you do not need independence from the platform, but at the same time they will not harm either. now the interesting part:

 void login () { cout << "======================================================" << "\n" << "\t\tWelcome to Bank Beta 0.1" << "\n" << "\t\t------------------------" << "\n\n" << "\t\t (1)Login" << "\n" << "\t\t (2)Create Account" << "\n\n"; gotoxy(0, 7); cout << "======================================================" << "\n"; gotoxy(0, 6); cout << "\t\t"; } int main() { int loginChoice; login(); gotoxy(0,8); cin >> loginChoice; _getch(); } 

Writing and reading are now independent of each other, and you can also go around all positions much easier.

+7
source

All Articles