Im trying to align my screen ouput. At the moment Ive been using setw and \t. They don't seem to line up correctly. I dont know why the first one hasn't got the got the correct alignment or y its different from all the others. My program is pretty complecated(well atleast it is to me) so I CANNOT simply adjust the first type and wage by simply doing this

cout << "       ";

ive also tried the following

cout << setw(n);
cout << "\t\t";

I just need to know how to align these up properly. is there any other ways?

ID NAME TYPE WAGE
1 Sam Casual $1640
2 Serena Casual $1640
3 Bryce Manager $2000
4 Fred Manager $2000
5 Grey P/T $1000
6 Bluey P/T $1000

Also does anone know how to export your file to a CSV file? If so where can I learn? Are there some good tutorials on the net? How do I save the output in a text file with the contents marked up with HTML? If anyone knows where I can learn that stuff that would be great...

CHEERS

Recommended Answers

All 3 Replies

you can use the width function

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
    cout.width(15);cout<<"Welcome\n";
    cout.width(15);cout<<"to DaniWeb\n";
cin.get();
return 0;
}

It will only help when you need right aligning.

The best way to deal with console text alignment issues is to get out a piece of graph paper and a stylus and draw what you want it to look like. Then you can count things out so that they always match.

As for the CSV stuff, give me a day or three to finish my CSV library (since the need seems to pop up regularly). CSV files are deceptively simple, so that caveats always catch people. The C++ version is pretty much done (it needs more testing still), but the C-version is a headache to deal with variable-length strings gracefully...

(You'll like the C++ version. It is all standard containers and can even translate data types for you using the standard stream operators... Its only about 300 lines of code total not counting boilerplate.)

Hey I have never tried what is posted below. But i think it might work out fine if you wish to align.

After the ID 01 And then you can give out a fixed length of setw(4);
After that when it comes to the NAME part maybe we can give it a space of (12) Characters in Total. And Then ..

string name;//This is where your name is stored
int id;
int x = (12-name.length());//Some variable which gives out the total value. So

cout<< id << setw(4); <<name <<setw(x);
//Might give you some result which is kinda starting at a the same point.

Or You can also try using spaces.

From the above.

void space (int a)
{
for (int b=0;b<=a;b++)
{
cout<<" ";
}

//Then in main something like this. 

int main()
{
cout<<ID;
space(4);
cout<<name;

Hope this work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.