Hi.
I'm experiencing a strange issue with cout. What it seems to boil down to is that if I have a bunch of consecutively numbered characters output next to each other in cout, the first two are displayed incorrectly --- they show up as the venus/mars symbols (♀ and ♂), which seems to be how the display shows the ASCII values 12 and 11 respectively.
I'm using Dev-C++ on Windows 7, and I haven't noticed anything like this on any other occasion.
Here is a minimal example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
char x = 92; // corresponds to '\'
while(x > 10)
{
cout << x;
x--;
}
return 0;
}
|
The output begins ♀♂ZYXWVUTSRQPONM..., whereas I would expect it to be \[ZYXWVUTSRQPONM...
I have tried several things, and observe the following:
- x = 92 is the highest number with this problem, starting at any value higher gives the output I would expect. Any number
below is again incorrect in the first two outputs
- Having the condition in the while loop be x > 11 gives an error only in the first output character, ♀[ZYXWVUTSRQPONM..., and is the number is higher than 11 gives the output I would expect.
- New lines in between characters (such as including a line cout << "\n"; in the loop) seems to make things output ok.
- For every starting value which causes the issue, if I output the starting character enough times first the output is fine,
e.g. if I have something like
1 2 3 4 5
|
int y = 10;
x = x - y;
for(int i = 0; i <= y; i++)
cout << x;
|
before the loop the output is fine, for any positive value of y.
- This doesn't occur if I output to a file.
I've tried searching on the web, and dev-cpp and windows forums, but so far haven't been able to find anything. Apologies if this is something really basic, but I can't seem to figure out what the issue is.