c++ cout extended ASCII characters

48 Views Asked by At

I want to make an application that prints out a bar graph of the frequencies of a number when two rand() function is added together.

#include <map>
#include <iostream>

int main() {
    std::map<int, int> freq;
    for (size_t i = 0; i < 100; i++)
    {
        freq[rand() / (float)RAND_MAX * 10 + rand() / (float)RAND_MAX * 10]++;
    }
    for (auto& i: freq)
    {
        std::cout << i.first << ":\t";
        for (size_t j = 0; j < i.second; j++)
        {
            std::cout << "▓";
        }
        std::cout << std::endl;
    }
}

unfortunately, when I print this character out, it result in a ? symble instead.

0:      ?
1:      ?
3:      ???????
4:      ????
5:      ???????
6:      ?????????
7:      ???
8:      ?????????????
9:      ???????
10:     ??????????
11:     ?????
12:     ???????????
13:     ????
14:     ??????
15:     ?????
16:     ????
18:     ??
19:     ?

I'm guessing this is because this character is an EXTENDED ASCII character and the iostream doesn't support it. I believed there are settings which I can turn on to make iostream work with EXTENDED ASCII characters, so can anyone tell me what this setting is? thank you.

0

There are 0 best solutions below