是否可以在Linux和Windows上使用EM DASH? [英] Is it possible to cout an EM DASH on Linux and Windows?

查看:69
本文介绍了是否可以在Linux和Windows上使用EM DASH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我是否将这样的内容放在cout语句中,我都无法找到 cout 一个 —字符的方法: cout<< —; 或使用 char(151),程序将打印出模糊的未定义字符。你们看到我的代码有什么问题吗? cout 甚至可以使用EM DASH吗?



编辑:我也尝试过 wcout<< L-; std :: wcout<< wchar_t(0x2014); 。两者都在我的终端上什么也没打印。

解决方案

首先,EM DASH是Unicode字符(只要确保您确实知道



打印Unicode字符取决于您打印的内容。
如果要打印到Unix终端(或仿真器),则终端仿真器正在使用支持该字符的编码,并且该编码与编译器的执行编码匹配,那么您可以按照上面的操作进行操作您的源代码 cout<< —;



如果您得到的是模糊的未定义字符,则您的终端可能不支持该字符。 / p>

如果您在Windows中(较难使用),则可以执行以下操作(不便于携带):

  #include< iostream> 
#include< io.h>
#include< fcntl.h>

int main(){
_setmode(_fileno(stdout),_O_U16TEXT);
std :: wcout<< L-;
}


I haven't been able to find a way to cout a '—' character, whether I put that in the cout statement like this: cout << "—"; or use char(151), the program prints out a fuzzy undefined character. Do you guys see anything wrong with my code? Is couting a EM DASH even possible?

Edit: I've also tried wcout << L"—"; and std::wcout << wchar_t(0x2014);. Those both print nothing in my terminal.

解决方案

First of all, EM DASH is an unicode character (just making sure you do know that).

Printing unicode characters depends on what you're printing to. If you're printing to a Unix terminal (or an emulator), the terminal emulator is using an encoding that supports this character, and that encoding matches the compiler's execution encoding, then you can do what you just did above in your source code cout << "—";

If you're getting fuzzy undefined characters, it is possible that your terminal just doesn't support that character.

If you're in windows (where it is harder), you can do something like this (which is not portable):

#include <iostream>
#include <io.h>
#include <fcntl.h>

int main() {
    _setmode(_fileno(stdout), _O_U16TEXT);
    std::wcout << L"—";
}

这篇关于是否可以在Linux和Windows上使用EM DASH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆