How to print your name middle on the console screen? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How to print your name middle on the console screen?

c++ basic program

27th Mar 2017, 8:30 AM
Harish kumawat
Harish kumawat - avatar
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
5th May 2017, 3:59 PM
Kirk Schafer
Kirk Schafer - avatar
+ 5
https://code.sololearn.com/c7zsyiA3Jtrm/?ref=app
5th May 2017, 4:00 PM
jay
jay - avatar
+ 2
Use required number of \t (tab) to move your name to the middle of the screen
27th Mar 2017, 11:55 AM
Vishnu ks
Vishnu ks - avatar
+ 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 ...
28th Mar 2017, 7:09 AM
mohamad mahjoob
mohamad mahjoob - avatar
0
use a lot of \n and \t
27th Mar 2017, 11:54 AM
Saqib Ali
Saqib Ali - avatar