-
setw newb help
Sorry about this, I'm very new to the c++ world. In all the books I've read and even the post I've found here, setw looks easy - but it's not working for me.
Example:
Code:
cout <<setw(20) <<"Fanzone Amusement Ticket Entry\n";
I'm trying to make "Fanzone Amusement Ticket Entry" sit in the, approximate, middle of a console app. I've been successfull by using spaces after the " and before the F but I know there's gotta be a better way.
When I use setw like above, I don't recieve any errors but "Fanzone Amusement Ticket Entry" stays to the far left.
Does setw not work with strings? If not, what will?
Any assistance is appreciated.
-
You could always do something like this:
Code:
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
string title("Fanzone Amusement Ticket Entry\n");
cout << setw(40+title.length()/2) << title;
return 0;
}
-
it;s because setw moves the print cursor over by the amount of spaces (20) and starts printing... the words move to the left... set the number higher and it should work fine...
-
Thank you both..
Thank you both. Never thought of the first way and didn't know the second would work. Both work like a champ though!