user-0 提问: 请教如何用C语言输出特殊字符

回复:
user: user-1
content: 难者不会，会者不难！ #pragma comment(lib,"user32") #pragma comment(lib,"gdi32") #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <windows.h> extern "C" HWND WINAPI GetConsoleWindow(); void HideTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);      if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = FALSE;         SetConsoleCursorInfo(hStdOut, &cciCursor);     } } void ShowTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);      if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = TRUE;         SetConsoleCursorInfo(hStdOut, &cciCursor);     } } int main() {     HWND  hwnd;     HDC   hdc;     HFONT hfont;     wchar_t wc[7]={0x25a3,0x25a4,0x25a5,0x25a6,0x25a7,0x25a8,0x25a9};      system("color F0");     system("cls");     HideTheCursor();     hwnd  = GetConsoleWindow();     hdc   = GetDC(hwnd);     hfont = CreateFont(16,0,0,0,0,0,0,0,GB2312_CHARSET,0,0,0,0,"MS Mincho");     SelectObject(hdc,hfont);     TextOutW(hdc,10,10,wc,7);     DeleteObject(hfont);     ReleaseDC(hwnd,hdc);     getch();     system("color 07");     system("cls");     ShowTheCursor();     return 0; }

user: user-0
content: 引用 2 楼 adlay 的回复:先看你这些字符是哪个编码里面的, 然后把你的终端改成对应的编码, 再输出这些字符对应的编码值 我用的是VS2013 ，输出窗口就是控制台。请问具体怎么实现 ?

user: user-2
content: 可以查找与之相对应的编码，即就是查找编码表。

user: user-3
content: 应该是有对应的编码的吧，连abc这些字符都需要对应的编码才能输出，哪些特殊的符号更是需要编码

user: user-4
content: 先看你这些字符是哪个编码里面的, 然后把你的终端改成对应的编码, 再输出这些字符对应的编码值

user: user-5
content: GBK 用 wchar输出 UTF8 用 char输出  这些特殊符号对应的编码 ，就只能google一下了

user: user-6

user: user-5
content: 引用 5 楼 chey0408 的回复:[quote=引用 2 楼 adlay 的回复:] 先看你这些字符是哪个编码里面的, 然后把你的终端改成对应的编码, 再输出这些字符对应的编码值 我用的是VS2013 ，输出窗口就是控制台。请问具体怎么实现 ?[/quote]  windows控制台下基本很难实现，windows控制台对Unicode编码支持的并不好 而你的这些特殊符号可能也没有对应的GBK编码 所以要么，你可以以utf-8的编码格式，输出到文件 要么你可以在linux控制台下面输出   #include <iostream> #include <fstream> #include "StringTool.h"  using namespace std; using namespace common::tool;  int main(int argc, char* argv[]) { 	// 	部分特殊符号的Unicode编码表 	// 	2000 - 206F：常用标点(General Punctuation) 	// 	2070 - 209F：上标及下标(Superscripts and Subscripts) 	// 	20A0 - 20CF：货币符号(Currency Symbols) 	// 	20D0 - 20FF：组合用记号(Combining Diacritics Marks for Symbols) 	// 	2100 - 214F：字母式符号(Letterlike Symbols) 	// 	2150 - 218F：数字形式(Number Form) 	// 	2190 - 21FF：箭头(Arrows) 	// 	2200 - 22FF：数学运算符(Mathematical Operator) 	// 	2300 - 23FF：杂项工业符号(Miscellaneous Technical) 	// 	2400 - 243F：控制图片(Control Pictures) 	// 	2440 - 245F：光学识别符(Optical Character Recognition) 	// 	2460 - 24FF：封闭式字母数字(Enclosed Alphanumerics) 	// 	2500 - 257F：制表符(Box Drawing) 	// 	2580 - 259F：方块元素(Block Element) 	// 	25A0 - 25FF：几何图形(Geometric Shapes) 	// 	2600 - 26FF：杂项符号(Miscellaneous Symbols) 	// 	2700 - 27BF：印刷符号(Dingbats) 	// 	27C0 - 27EF：杂项数学符号 - A(Miscellaneous Mathematical Symbols - A) 	// 	27F0 - 27FF：追加箭头 - A(Supplemental Arrows - A) 	// 	2800 - 28FF：盲文点字模型(Braille Patterns) 	// 	2900 - 297F：追加箭头 - B(Supplemental Arrows - B) 	// 	2980 - 29FF：杂项数学符号 - B(Miscellaneous Mathematical Symbols - B) 	// 	2A00 - 2AFF：追加数学运算符(Supplemental Mathematical Operator) 	// 	2B00 - 2BFF：杂项符号和箭头(Miscellaneous Symbols and Arrows) 	wchar_t wsc[0xC00]; 	for (int i = 0; i < 0xC00; i++) 	{ 		wsc[i] = 0x2000 + i; 	}  	// Unicode -> Utf8 	wstring unicode(wsc); 	string utf8; 	utf8.resize(StringTool::UnicodeToUtf8Length(unicode)); 	StringTool::UnicodeToUtf8(utf8, unicode);  	// 输出到控制台 	cout << utf8 << endl;  	// 输出到文件 	ofstream file; 	file.open("1.txt", ios::out | ios::trunc); 	if (file) 	{ 		file.write(utf8.c_str(), utf8.length()); 		file.flush(); 		file.close(); 	}  	return 0; }

user: user-1
content: 仅供参考：#pragma comment(lib,"user32") #pragma comment(lib,"gdi32") #include <stdlib.h> #include <conio.h> #include <windows.h> HWND WINAPI GetConsoleWindow(); void HideTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);     if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = FALSE;         SetConsoleCursorInfo(hStdOut, &cciCursor);     } } void ShowTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);     if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = TRUE;         SetConsoleCursorInfo(hStdOut, &cciCursor);     } } int main() {     HWND  hwnd;     HDC   hdc;     HFONT hfont;     HBITMAP hbm;     HDC hdcBits;     BITMAP bm;      system("color F0");     system("cls");     HideTheCursor();     hwnd  = GetConsoleWindow();     hdc   = GetDC(hwnd);     hbm=LoadImage(0,"C:\\Windows\\Soap Bubbles.bmp",IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);     if (hbm) {         hdcBits = CreateCompatibleDC(hdc);         GetObject (hbm, sizeof(BITMAP), &bm);         SelectObject(hdcBits,hbm);         BitBlt(hdc,200,10,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);         DeleteDC(hdcBits);         DeleteObject(hbm);     }     hfont = CreateFont(24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");     SelectObject(hdc,hfont);     SetTextColor(hdc,RGB(255,255,255));     SetBkMode(hdc,TRANSPARENT);     TextOut(hdc,210,30,"这个背景是泡泡",14);     DeleteObject(hfont);     ReleaseDC(hwnd,hdc);     getch();     system("color 07");     system("cls");     ShowTheCursor();     return 0; }