trouble with cout formatting

It seems that setiosflags isn't even working here. I could set any of them right or left and the output on my screen looks the same. I'm running g++ in gnome-terminal. Any ideas?

I'm trying to get the part with setfill ('-') to be aligned to the left, but it stays right justified no matter what I specify.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
cout << endl << endl
     << setw(40) << setfill('*') << setiosflags(ios::left) << ""
     << setw(7) << setfill(' ') << ""
     << setw(25) << " First Investor's Heaven "
     << setw(7) << ""
     << setw(41) << setfill ('*') << setiosflags(ios::right) << ""
     << endl
     << setw(40) << setiosflags(ios::left) << ""
     << setw(7) << setfill(' ') << ""
     << setw(21) << " Financial Report "
     << setw(11) << ""
     << setw(41) << setfill ('*') << setiosflags(ios::right) << "";

cout << endl;
cout << endl;

cout.fill (' ');
cout << setw(15) << "Stock Symbol";
cout << setw(15) << "Open";
cout << setw(15) << "Today Close";
cout << setw(15) << "High";
cout << setw(15) << "Low";
cout << setw(15) << "Prev Close";
cout << setw(15) << "% Gain";
cout << setw(15) << "Volume"; 

cout << endl;
cout.fill ('-');

cout << setw(15) << setiosflags(ios::left) << " ";
cout << setw(15) << " ";
cout << setw(15) << " ";
cout << setw(15) << " ";
cout << setw(15) << " ";
cout << setw(15) << " ";
cout << setw(15) << " ";
cout << setw(15) << " "; 
cout << endl <<  setiosflags(ios::right);

cout.fill(' ');
Add a space before changing the fill.

1
2
3
cout << endl;
cout << " ";
cout.fill ('-');


Also, standard console windows should be restricted to no more than 80 characters. Meaning, your display is about 150% bigger than it really should be.
Got everything to work by using "left" and "right" in place of "setiosflags(ios::left)" and "setiosflags(ios::right)", respectively. What was I doing wrong with the first method?
ios::left and ios::right aren't the values you wanted. I believe simply left and right would have worked within your call to setiosflags. Long story short, ios::right was a certain value, but not what you wanted. Same with ios::left.
Why the space before changing the fill?
No particular reason for it, but it does force the hypens over by one which is what I thought you wanted.
Topic archived. No new replies allowed.