right in iomanip misfunctions
Sep 28, 2012 at 10:00pm UTC
I've always tried using right in manipulating the ostream object cout, but it has never worked in my whole life! Even on the most basic Hello world programme?
I need help. This is the code:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout<<right<<"Hello World!" ;
cin.get();
return 0;
}
Sep 28, 2012 at 10:54pm UTC
Set the width first
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout<<setw(20)<<right<<"Hello World!\n" ;
cout<<setw(20)<<left<<"Hello World!\n" ;
return 0;
}
Last edited on Sep 28, 2012 at 11:02pm UTC
Sep 29, 2012 at 9:32am UTC
Thank you very much it WORKS!
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout<<setw(80)<<right<<"Hello World!" ;
cin.get();
return 0;
}
Topic archived. No new replies allowed.