Printing any box drawing character permanently kills wcout

Dec 6, 2018 at 12:34pm
There's some weird issue with my program that's been torturing me for like 2 hours. This is my last day and I need to get this done ASAP, and I don't know anyone personally who doesn't suggest stupid things like "does your compiler support Unicode?" "does your terminal support Unicode?" "have you tried recompiling/restarting your computer?"

Anyway, I have this specific issue with wcout. When printing any box drawing character (e.g. ) it completely stops working. As in, wcout can no longer be used. It shuts down, freezes, whatever.

However, printf, wprintf, and even regular cout still work with box drawing characters. They have no issue.

What's going on here? Can someone please help me with this?
Last edited on Dec 6, 2018 at 12:35pm
Dec 6, 2018 at 1:17pm
Dec 6, 2018 at 1:18pm
Yes, but let me try that method. I was using setlocale(LC_ALL, "");.

Aaand on testing it... it doesn't work. Switching back to setlocale.
Last edited on Dec 6, 2018 at 1:18pm
Dec 6, 2018 at 1:25pm
What are you outputting to?

Does the program stop running or is it just that you cannot see any output?

You might want to post a small example that demonstrates the problem so that we can see if you do something wrong in the code
Last edited on Dec 6, 2018 at 1:27pm
Dec 6, 2018 at 1:30pm
It doesn't stop running, wcout just stops working.

With this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <clocale>

int main() {
	setlocale(LC_ALL, "");

	std::wcout << L"x┌y" << std::endl;

	for (size_t i = 0; i < 1000000; i++) {
		std::wcout << L"You will not see me" << std::endl;
	}

	std::wprintf(L"x1┌y1\n");

	std::cout << "x2┌y2" << std::endl;
}


I get the output:

1
2
xx1┌y1
x2┌y2


Without the setlocale, I get xx1x2┌y2.

I would advise removing the for loop just in case you get it working :)
Dec 6, 2018 at 1:53pm
It works for me on Linux (Debian), and prints "You will not see me" over and over again, except for the output on line 15 that is not printed. Apparently, you're not supposed to mix wide and narrow characters when outputting to stdout. If I change line 15 to use wide characters it works fine.
Last edited on Dec 6, 2018 at 1:56pm
Dec 6, 2018 at 2:00pm
What compiler/OS are you using? I'm (or rather my IDE is) using clang-1000.10.25.5 on macOS 10.14.

Apparently, you're not supposed to mix wide and narrow characters with stdout

Then line 7 would work. and line 15 wouldn't.
Last edited on Dec 6, 2018 at 2:01pm
Dec 6, 2018 at 2:22pm
What compiler/OS are you using?

I used GCC on Linux (Debian).

Then line 7 would work. and line 15 wouldn't.

Yes, that's what happened to me.

I'm (or rather my IDE is) using clang on macOS 10.14.

Do you know if you're using libstdc++ or libc++? A quick search seems to suggest that there are some problems with libstdc++'s handling of locales on mac.

user657267 wrote:
As libstdc++ does not support anything but the 'generic' locale model on OSX, C++ locales are hardly supported at all. Your segfault is caused by facet.table(); returning a null pointer (this is not actually allowed by the standard).
https://stackoverflow.com/questions/25130927/stdlocale-segfault-on-os-x-cannot-reproduce-on-any-other-platform#answer-25131471

bames53 wrote:
if you're using libstdc++ you should know that it doesn't support locales properly on OS X. You'll have to use libc++ in order for OS X's locale names (e.g., "en_US.UTF-8") to work.
https://stackoverflow.com/questions/11512656/how-to-print-c-wstring-utf-8-characters-to-mac-os-or-unix-terminal#answer-11515035
Dec 6, 2018 at 2:31pm
Do you know if you're using libstdc++ or libc++? A quick search seems to suggest that there are some problems with libstdc++'s handling of locales on mac.


Changing the stdlib doesn't change the behavior. Changing the compiler to clang++ causes iostream to not be found.

I used GCC on Linux (Debian).


Using GCC on macOS yields the same, wcout-less result. I don't know what's going on...
Dec 6, 2018 at 2:34pm
What does the string returned by setlocale say?
Dec 6, 2018 at 2:35pm
C/en_US.UTF-8/C/C/C/C
Dec 6, 2018 at 2:51pm
I don't really know what that to make of that to be honest.

Forgive me for asking but Is there a reason why you want to use wide characters? Regular narrow characters seems to be much less of a hassle.
Dec 6, 2018 at 2:53pm
You asked what the string returned by setlocale said, that's the entire string.

Is there a reason why you want to use wide characters?


My entire library uses wstring rather than string.
Dec 6, 2018 at 3:09pm
You asked what the string returned by setlocale said, that's the entire string.

You did nothing wrong. I was just hoping that it would say "C", or be a null pointer, something that's obviously wrong. For me it returns a single locale name ("en_US.utf8") so I don't know how to interpret all those slash separated Cs.

My entire library uses wstring rather than string.

OK, well, I'm afraid I won't be able to help you. Hopefully someone who has more experience with wide characters on MacOS can be of more help.
Dec 6, 2018 at 3:11pm
Well, setlocale(LC_ALL, "en_US.UTF-8") returns just en_US.UTF-8, but it still doesn't print the box drawing characters correctly.
Dec 6, 2018 at 3:36pm
About your problems with clang++... this is just a shot in the dark, but did you read the comments posted below on this SO answer? https://stackoverflow.com/a/25141428/8690169
(It's from the same page that Peter linked.)

If the problem is that it can't find standard library headers like <iostream>, it that sounds fixable:

https://stackoverflow.com/questions/26333823/clang-doesnt-see-basic-headers
https://stackoverflow.com/questions/29180184/clang-can-not-locate-c-header-and-library
https://www.reddit.com/r/cpp_questions/comments/6ddks2/clang_unable_to_find_iostream/
Dec 6, 2018 at 10:40pm
Switched to std::wprintf and everything is fine now. Sorry, lol
Topic archived. No new replies allowed.