+ 5
How to print your name middle on the console screen?
c++ basic program
5 Answers
+ 5
Sorry to add late; this might be generally useful (also @jay's code; nice).
To determine start position, you need the terminal width and the width of the string. Let's say the terminal is 160 characters across, and your string is 23.
160/2 is halfway. You can either subtract half of 23 (80-12 = 68) or combine it in one operation:
xPosition = (termWidth - myStrWidth) / 2;
Now for the "bad news". To programmatically find out how big the terminal is, you probably have to ask the GUI API:
http://stackoverflow.com/questions/23369503/get-size-of-terminal-window-rows-columns
You may have better (simpler) luck with a recent version of 'curses' (ncurses / pdcurses)...this link is what it looks like:
http://www.freebasic.net/forum/viewtopic.php?t=3158
+ 5
https://code.sololearn.com/c7zsyiA3Jtrm/?ref=app
+ 2
Use required number of \t (tab) to move your name to the middle of the screen
+ 1
with gotoxy you can move cursor anywhere in console .
if gotoxy don't work in your compiler:
header file : windows.h and iostream
void gotoxy(int x ,int y)
{
HANDLE a;
COORD b;
cout.flush();
b.X=x;
b.Y=y;
a=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(a,b);
}
don't forget up vote ...
0
use a lot of \n and \t