简体   繁体   中英

iostream prints ellipses wrong

I have a simple piece of example code

#include <string>
#include <stdio.h>
#include <iostream>

int main ()
{
    std::cout << "Connecting to hello world server…" << std::endl;
    printf ("Connecting to hello world server...\n");

    while(true)
    {
    }
}

In the console window the first line prints the ellipses as an 'a' character with a tilde above it, where the second line prints as expected.

Can someone explain why this is happening?

The first line does not have "..." but a single character "…"

Change:

 std::cout << "Connecting to hello world server…" << std::endl;

to

 std::cout << "Connecting to hello world server..." << std::endl;

您的第一个椭圆是unicode水平省略号,而第二个是连续三个周期。

In the first one, you have a single character known as HORIZONTAL ELLIPSIS .

In the second, it is 3 period s

As the others have explained, the first is using a single Unicode character NEXT LINE (NEL) (U+0085) while the second uses three periods.

As to why the first doesn't work, it's a limitation of the console window. It doesn't work in Unicode like the rest of Windows, it works with code pages. The numeric values of most characters will be completely different than their Unicode counterparts, so the wrong character will be printed.

In this case the \\x85 character in Code page 437 is the à that you see.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM