0

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.

JaMiT
  • 14,422
  • 4
  • 15
  • 31
silver takana
  • 138
  • 12
  • What's that character's ASCII? – kiner_shah Dec 09 '21 at 05:29
  • https://godbolt.org/z/EYz3Yjndq outputs it fine. What console are you using? – Passerby Dec 09 '21 at 05:42
  • Other potential duplicates: [Getting a '?' in the Output when printing special (Extended) ASCII characters using `std::cout`](https://stackoverflow.com/questions/64098108/) and [Streaming Out Extended ASCII](https://stackoverflow.com/questions/35747864/) and [print a filled square in console](https://stackoverflow.com/questions/26438222/) – JaMiT Dec 09 '21 at 06:35

0 Answers0