473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

right alignment of output

I am trying to right justify some of my output and it is not working right. Everything before I try and reset the alignment needs to be left aligned and everything after should be right aligned.

My code for the output is:

string spacer(" ");
cout << setiosflags(ios::fixed) << setprecision(2);
cout <<setiosflags(ios::left)<<setw(15)<<peeps[j].first
<<setw(2)<<" "<<peeps[j].age
<<setw(4)<<spacer<<peeps[j].gender
<<resetiosflags(ios::left)
<<setw(5)<<spacer<<peeps[j].val
<<setw(3)<<spacer<<peeps[j].type
<<setw(4)<<spacer<<peeps[j].dist
<<setw(4)<<spacer<<peeps[j].city
<<setw(4)<<spacer<<peeps[j].viol
<<setw(4)<<spacer<<peeps[j].accid
<<spacer<<setw(4)<<pts
<<spacer<<premium<<'\n';

I can't seem to find what I am doing wrong with this.
Jul 17 '07 #1
1 3642
weaknessforcats
9,208 Expert Mod 8TB
To right-justify:

cout << right << data;

To left-justify (default);

cout << left << data;

This assumes you have already set the field width.
Jul 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: deanfamily11 | last post by:
Ok, here's another problem I'm having. I've tried several different things, but I just can't get anything to be right justified. Any thoughts? #include <iostream> #include <iomanip>...
8
by: mrby | last post by:
Hi,guys, char s1 = "abcde"; char s2; printf("%d",s1-s2); What should be the result on a 32-bit machine? It is 8 on my machine, why? Here is the output of "uname -a" on my machine:
7
by: shawnk | last post by:
Hello Everyone How do you format format numbers right-justified using Console.WriteLine(), i.e I need to line up numbers in vertical columns and the MSDN documentation is pretty poor Here is the...
5
by: Hendrik Schober | last post by:
Hi, we just run into the problem, that "default" alignment in the project properies dialog seem to be different. We have a project that's a DLL, which is linked with a couple of LIBs. All are...
7
by: Earl | last post by:
Any known fixes for the wacky right-alignment bug in the WinForms datagrid (VS2003)? I've tried Ken's workaround...
3
by: Bill Pursell | last post by:
I have a program that does most of its work traversing a bunch of lists. The lists contain a void *, and I spent some time today replacing the void *'s with a copy of the data at the end of the...
11
by: Brian Gladman | last post by:
A lot of low level cryptographic code and some hardware cryptographic accelerators either fail completely or perform very poorly if their input, output and/or key storage areas in memory are not...
5
by: xmllmx | last post by:
Please forgive me for cross-posting. I've post this to microsoft.publoc.vc.mfc. But I can't get any response. Maybe only MFC- related topics are cared there. To begin with code: union XXX {...
12
by: Kevin | last post by:
Hey, I was hoping someone out here might be able to clue me in on some alignment issues I'm having. Hopefully I can explain this best through code below. ACSign and MyACSign functions below get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.