showpos output issue

I am trying to output numbers in an array called memory in this format: +0005
(given that that location in the array holds the integer 5).

My output is basically this: cout << setfill('0') << setw(4) << memory[i];
The problem is when I try to incorporate the showpos manipulator like so:

cout << showpos << setfill('0') << setw(4) << memory[i];

The output looks like this: 000+5 or 00+5, I can't exactly remember.
Either way that's not the output I want. Any suggestions?
Thanks.
Can you post your entire code in code brackets so we can better understand the context?
The entire program is very lengthy. This is a snippet from one of the functions of the program. The output should look similar to this :

Memory: 
      0     1     2     3     4     5     6      7     8     9 
0  +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
10 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
20 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
30 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
40 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
50 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
60 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
70 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
80 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
90 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000


And it does, except for those darned +'s.

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
/************************************************************************
	 *                                                                      *
	 *                             Memory Dump                              *
	 *                                                                      *
	 ************************************************************************/
	blanklines(1);
	cout << "  Memory:";
	blanklines(1);

	//rows
	for (int j = 0; j < 10; j++)
	{
		if (j == 0)
		{
			cout << "\t ";
		}
		cout << j << " " << setw(4);
	}

	blanklines(1);

	for (int i = 0; i < size; i++)
	{
	//columns
	if (i == 0)
		{ cout  << i << "\t"; }
	if (i == 10 || i == 20 || i == 30 || i == 40 || i == 50
			|| i == 60 || i == 70 || i == 80 || i == 90)
			{ cout << endl << "   " << i << "\t"; }

	//memory
	cout << " " << setfill('0') << setw(4) << memory[i];
	}

	//seperate output from environment text
	blanklines(5);

	return Done = true;
}


?
You need to add the I/O manipulator std::internal or its equivalent. http://cplusplus.com/reference/iostream/manipulators/internal/
Last edited on
Topic archived. No new replies allowed.