为了在 C++ 中获得某些特殊字符,我们可以将八进制值的转义序列括在单引号内,因此 '\nnn'
其中 nnn
是一个八进制代码。
我目前知道的唯一例子是'\370'
度数符号 (°)。
在 C++ 中打印非简单 ascii 字符的其他此类值的列表在哪里?
在 ascii-code.com 的代码表中这是两个条目吗
DEC OCT HEX BIN Symbol HTML Number HTML Name Description
176 260 B0 10110000 ° ° ° Degree sign
248 370 F8 11111000 ø ø ø Latin small letter o with slash
对于我的问题,这显然不是正确的——即分配 '\nnn'
到 char
变量或通过 cout <<
插入输出流在 Visual Studio 2015 中。
正确的表格在哪里?它与“代码集”有关,但我不知道 VS 2015 中的默认代码集是什么或如何更改代码集。
下面有人建议我“使用 \u####
,其中 ####
是一个代表所需字符的 Unicode 值的数字。例如 \u2014
将打印一个 — (em-dash)。”然而,当我尝试那个例子——或来自 rapidtables.com/code/text/unicode-characters 的任何其他例子时或 wikipedia.org/wiki/List_of_Unicode_characters – 我没有得到给定代码所需的字符。例如,\20AC
应该产生一个欧元符号 (€),但我得到了一个带有 cedilla (Ç) 的大 C。在 Visual Studio 2015 中用 C++ 打印特殊字符的 Unicode 值表在哪里?
最佳答案
在 Visual Studio 2013 中准备的 C++ 控制台应用程序的下一个代码可能会有所帮助。 Based on this answer .
// 37645602.cpp : Defines the entry point for the console application.
//
#include "stdafx.h" // added by Visual Studio
#include <fstream>
#include <iostream>
#include <codecvt>
#include <locale>
#include <fcntl.h>
#include <io.h>
const wchar_t* testArray[] =
{
L"€ ° ø — ď π щ", // for debugging
L"\u20AC \u00b0 \u00F8 \u2014 \u010f \u03c0 \u0449" // the same characters
};
int _tmain(int argc, _TCHAR* argv[])
{
_setmode(_fileno(stdout), _O_U16TEXT);
for (int j = 0; j < 2; ++j)
{
std::wcout << testArray[j] << L'\n';
}
return 0;
}
输出:
==> 37645602.exe
€ ° ø — ď π щ
€ ° ø — ď π щ
使用拉丁文、斯拉夫文、西里尔文和希腊文字符的混合测试(从类似于此 Alt KeyCode Finder 的脚本输出):
==> altcodes "€°ø—ďπщ"
Ch Unicode Alt? mod 256 UTF-8 IME 0405/cs-CZ; CP852; ANSI 1250
€ U+20AC 8364 …172… 0xE282AC Euro Sign
° U+00B0 176 …176… 0xC2B0 Degree Sign
ø U+00F8 248 …248… 0xC3B8 Latin Small Letter O With Stroke
— U+2014 8212 …20… 0xE28094 Em Dash
ď U+010F 271 …15… 0xC48F Latin Small Letter D With Caron
π U+03C0 960 …192… 0xCF80 Greek Small Letter Pi
щ U+0449 1097 …73… 0xD189 Cyrillic Small Letter Shcha
€°ø—ďπщ
关于c++ - 在 C++ 中打印特殊符号的值表在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37645602/