MistyD
MistyD

Reputation: 17253

utf8 equivalent not displaying correct

I am using the following code

int main()
{
    std::string str="\xc2b1";
    std::cout << str;
}

Now according to this c2b1 is equivalent to PLUS-MINUS SIGN However when I run this code on coliru I get the symbol

Is this an issue with the compiler ? Or am I doing something wrong I was expecting the symbol

±

Any suggestions would be appreciated.

Upvotes: 1

Views: 64

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126937

\xc2b1 is asking to the compiler for a byte of value 0xc2b1, which isn't possible on pretty much any "normal" platform with 8-bit bytes.

What the site you linked is trying to say is that the code point (≈character) U+00B1 is expressed as a sequence of two UTF-8 code units (=bytes), specifically C2 B1. So, you have to write the two bytes as two separate escape sequences, i.e. "\xc2\xb1".

Upvotes: 5

Related Questions