Hi all!
I have a little problem here, I would like the width function in cout applied to all the sucesive outputs. However, it is only applied to the next output only, I mean, with this code I get
0:00:10:20:30:4
1:01:11:21:31:4
2:02:12:22:32:4
3:03:13:23:33:4
4:04:14:24:34:4
5:05:15:25:35:4
6:06:16:26:36:4
7:07:17:27:37:4
8:08:18:28:38:4
9:09:19:29:39:4
and I would like
0:0 0:1 0:2 0:3 0:4
1:0 1:1 1:2 1:3 1:4
2:0 2:1 2:2 2:3 2:4
3:0 3:1 3:2 3:3 3:4
4:0 4:1 4:2 4:3 4:4
5:0 5:1 5:2 5:3 5:4
6:0 6:1 6:2 6:3 6:4
7:0 7:1 7:2 7:3 7:4
8:0 8:1 8:2 8:3 8:4
9:0 9:1 9:2 9:3 9:4
#include <iostream>
using namespace std;
int main(void)
{
cout.width(8);
cout.setf(std::ios::fixed | std::ios::right);
for (int row = 0; row < 10; ++row) {
for (int column = 0; column < 5; ++column) {
cout << row << ":" << column;
}
cout << endl;
}
return 0;
}
I realize that by moving the cout.width inside the loop but do the trick in this example, but not in one without a loop resulting in having to specify the width in every output.
My question is, is there a way in which the width function applies to everything that goes after it?
Thank you in advance!