Inserting a “£” sign in an output string in C++

前端 未结 4 1094
不思量自难忘°
不思量自难忘° 2021-01-06 00:10

I have the following code:

cout << \"String that includes a £ sign\";

However, the £ sign is not being recognised by the compiler, an

4条回答
  •  旧时难觅i
    2021-01-06 00:47

    ASCII only defines characters up to 127. (The 8th bit was intened for parity, which was needed for the noisy transmission line of the 1960s when ASCII was designed) Beyond that, the characters vary by code page and font. There is a discrepancy between the font used by the editor you use to write your C++ code, and the font used by whatever is displaying the output.

    So, you need to display character 156 to display a £ on your output device. You can explicitly enter a character 156 on a WIndows PC, by holding done the Alt key and pressing "0159" on the numeric keyped. Alternately, you can use a character code in the string in hex:

     cout << "String that includes a \x9C sign"; 
    

提交回复
热议问题