I am trying to find a way to center output on the screen. The output will vary in length so I can not just pad with a set number of spaces. My output looks like this:
cout << fixed; cout.precision(2); cout << "Your login ID is " << loginID << endl; cout << "Your password is " << password << endl; cout << "The beginning balance on your account is $" << balance << endl;
The loginID, password and balance variables can very in length and I would really like to have this output centered in the console. Any suggestions? Is it possible to get the text and the variable assigned to a string, get the length of the string, subtract from 80 and divide by 2 to pad left side with that many spaces? Is getting the text and variable into a string called casting? I have not had any luck with this so far.
I'm new to C++, please be kind... Thanks for any input!