align cin and cout

Hello,

I was wondering the easiest way to align cin and cout. For example some of my cout messages will need to be aligned left, right, and center.
Well the big totally specific to your system problem you need to solve is figuring out the width of your console / terminal.

After that, it's basic maths.
ah ok, I am running windows. I will look into then. Thank you.
there is (or was) a compiler extension (like getch) command in windows: gotoxy(x,y) that lets you type anywhere. It is extremely useful if you don't want to do this the hard way.

are you just wanting it for the default console settings or variable to user's settings? That is harder. You will as noted above need to fetch the width etc from the OS to do a variable one.
Last edited on
TBH, if you just want to get 99% of the code working, you can start with

1
2
3
int getScreenWidth() {
  return 80;
}


For most tutorial / student examples, that's all you need.

If you need real widths from real consoles on real machines, then you only have to change the inside of the function. Everything else you've done will be complete unaffected.
Topic archived. No new replies allowed.