-1

Whenever I compile the program and run it, if the output contains some binary code or any symbols, like ?, heart, ! something like that, it never shows up. enter image description here

Is there anyone has same problem or anyone who knows how to solve it? My window is not in Korean, but I am using Korean Keyboard with U.S. like:

enter image description here

My local and any other things are set up with U.S.

Jieun Chon
  • 139
  • 1
  • 10

2 Answers2

0

Supposed your code (which you unfortunately don't show in your question) is something like

int main() {
    int n = 4;
    float n2 = 4;
    char n = 4;

    std::cout << n << std::endl;
    std::cout << n1 << std::endl;
    std::cout << n2 << std::endl;
}

You should acknowledge that char values should be initialized using '4' to get a printable character.

These can also be numbers, but you need to put the correct character encoding codes then, that are supported by your targets environment.

The most common encoding nowadays is ASCII, where the correct decimal equivalent for 4 is encoded as 52 as decimal number.

C++ provides different overloads of the std::ostream& operator<<(std::ostream&, type) for all of the mentioned types like int, float and char. Rendering the numerical types is already done automatically.

If you actually want to render the numerical value contained from char n2, simply cast it.


My window is not in Korean, but I am using Korean Keyboard with U.S. like: ...

Your keyboard settings don't have any relevance here.

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
-1

Change

char n2 = 4; 

to

char n2 = '4';
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Cajuu'
  • 1,154
  • 2
  • 19
  • 50
  • 1
    If you answer a question, do it completely. Just fixing the code, isn't a great explanation (didn't downvote BTW, but won't upvote either, for the reason I gave). – πάντα ῥεῖ Sep 24 '15 at 16:27
  • Agreed - add some explanation as to why this is the solution, to help others understand the underlying logic, so they can avoid similar mistakes in the future. – CodeMouse92 Sep 24 '15 at 19:41