how do you right align using <iostream.h>?
i've tried:
Code:... cout.setf(ios::right); ...Code:... cout.setf(ios::right); cout<<right; ...Code:... cout<<setiosflag(ios::right)<<...; ...
how do you right align using <iostream.h>?
i've tried:
Code:... cout.setf(ios::right); ...Code:... cout.setf(ios::right); cout<<right; ...Code:... cout<<setiosflag(ios::right)<<...; ...
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
The simple manipulator is easiest:
Code:#include <iostream.h> #include <iomanip.h> int main() { cout<< right << setw(20) <<"Hello, world!"<<endl; return 0; }
My best code is written with the delete key.
Hi,
First, don't use header files with .h extensions. Use the equivalent header files, and read about the using directive here:
http://www.cplusplus.com/doc/ansi/hfiles.html
Second, output using cout is right aligned by default, but every field is the exact width of what you output, so the right side is ragged. All you have to do to right align output is set the width of all the fields the same:
#include<iomanip> //for setw()
#include<iostream> //for cout
using namespace std;
cout<<setw(25)<<"See Jane run."<<endl;
cout<<setw(25)<<"See Jane fall down."<<endl;
Last edited by 7stud; 06-04-2003 at 12:25 PM.
that would be helpful if i wasn't using an outdated compiler...Originally posted by 7stud
First, don't use header files with .h extensions. Use the equivalent header files, and read about the using directive here:
http://www.cplusplus.com/doc/ansi/hfiles.htmli want a predefined right though...Originally posted by 7stud
Second, output using cout is right aligned by default, but every field is the exact width of what you output, so the right side is ragged. All you have to do to right align output is set the width of all the fields the same:
thanks prelude... i'll try that later (i can't do it now - it's on a school compiler and the professor asked me how to do it, but none of the ways i tried helps...
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
You could always try
instead ofCode:cout.setw( 25 ); cout<<"bah"<<endl;
Code:cout<setw( 25 )<<"bah"<<endl;
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
but the setw(25) is only if the width of the console is 25 characters, i think
This might be old but I thought i'd help some of you out...
If you have "cout << right << num1 << num2 << num3 << num4;
I don't think num2,3,4, will have the right align. Doesn't seem to work that way. You have to separate:
Code:cout << fixed << right << setw(4) << setprecision(2) << num1; cout << fixed << right << setw(4) << setprecision(2) << num2;
★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★