JME
JME

Reputation: 2353

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?

Upvotes: 1

Views: 246

Answers (4)

Mark Ransom
Mark Ransom

Reputation: 308246

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.

Upvotes: 1

Arjun Sreedharan
Arjun Sreedharan

Reputation: 11453

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

In the second, it is 3 periods

Upvotes: 1

Alden
Alden

Reputation: 2269

Your first ellipses is a unicode horizontal ellipsis, whereas your second is three consecutive periods.

Upvotes: 1

Grzegorz
Grzegorz

Reputation: 3335

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;

Upvotes: 5

Related Questions