Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

aeleneski

i

This topic is 5381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
To my knowledge, there is no function specifically made to center text. Your best bet would be to tab it into the center by printing "\t" a bunch of times.

For example:
std::cout << "\t\t\t\tMy Text!" << endl;
(Not sure of the exact number of tabs.)

Share this post


Link to post
Share on other sites
Use simple math to figure out where it should go (you''d start writing at half the width of the console window minus the half the length of the string) and then use spaces to get it there.

Share this post


Link to post
Share on other sites
Like I said:
start writing at (Total Console Line length - your text length)/2

Use blank spaces to start writing at the desired position.

Share this post


Link to post
Share on other sites
To elaborate what Lektrix said (Lektrix, you are right, just want to make it a bit clear for him)

Say you have std::string name = "Hello this is soooo long";
to get the size, all you would have to do would be:

std::string length = name.size();

And now length contains the string size.

Cheers

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!