Jump to content
php.lv forumi

Recommended Posts

Posted (edited)

Sveiki! Kādu funkciju (visprimitivāko) ir jāizmanto lai varētu centrēt tekstu konsolē ? C++ .

 

cout<<"                 ##########################";

Ar spaciem kaut kā nekatit smile3.gif

Edited by Seal
Posted

Noskaidro cik simboli ir konsoles rindaa (80, iespējams)

 

Teiksim. lai iecentrētu burtu A, tas ir jāieraksta kā 40. simbols (40 atstarpes pirms A)

 

Lai ierakstītu jau vārdu,formula varētu būt tāda:

 

pozīcija = 40 - (vārda gadījums / 2)

 

 

tad,

//Izdrukājam atsrapes

for(i=0; i<pozīcija; i++){

cout << " ";

}

 

// Izdrukājam vārdu

cout << vards

Posted (edited)

vai dažāda izmēra konsolei:

 

#include <ncurses.h>
#include <string.h>
int main(void)
{
const char * slogan = "c++ rules the world!";
int consx, consy;
initscr();
getmaxyx(stdscr, consy, consx);
printw("size of console (%d, %d) \n\n\n\n", consx , consy);
for(int i = 0; i < (consx - strlen(slogan)) / 2; i++)
printw(" ");
printw(slogan);
getch();
endwin();
return 0;
}

Edited by ieleja

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...