我想输出这张脸 我看到的只是问号符号
void win(){
cout << "░░░░█▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█" << endl;
cout << "░░░░█▒▒▄▀▀▀▀▀▄▄▒▒▒▒▒▒▒▒▒▄▄▀▀▀▀▀▀▄" << endl;
cout << "░░▄▀▒▒▒▄█████▄▒█▒▒▒▒▒▒▒█▒▄█████▄▒█" << endl;
cout << "░█▒▒▒▒▐██▄████▌▒█▒▒▒▒▒█▒▐██▄████▌▒█" << endl;
cout << "▀▒▒▒▒▒▒▀█████▀▒▒█▒░▄▒▄█▒▒▀█████▀▒▒▒█" << endl;
cout << "▒▒▐▒▒▒░░░░▒▒▒▒▒█▒░▒▒▀▒▒█▒▒▒▒▒▒▒▒▒▒▒▒█" << endl;
cout << "▒▌▒▒▒░░░▒▒▒▒▒▄▀▒░▒▄█▄█▄▒▀▄▒▒▒▒▒▒▒▒▒▒▒▌" << endl;
cout << "▒▌▒▒▒▒░▒▒▒▒▒▒▀▄▒▒█▌▌▌▌▌█▄▀▒▒▒▒▒▒▒▒▒▒▒▐" << endl;
cout << "▒▐▒▒▒▒▒▒▒▒▒▒▒▒▒▌▒▒▀███▀▒▌▒▒▒▒▒▒▒▒▒▒▒▒▌" << endl;
cout << "▀▀▄▒▒▒▒▒▒▒▒▒▒▒▌▒▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▒▒█" << endl;
cout << "▀▄▒▀▄▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▄▄▄▄▒▒▒▒▒▒▄▄▀" << endl;
cout << "▒▒▀▄▒▀▄▀▀▀▄▀▀▀▀▄▄▄▄▄▄▄▀░░░░▀▀▀▀▀▀" << endl;
}
答案 0 :(得分:3)
如果您使用的是Windows,则以下代码的工作原理如下:
UTF-8 w/ BOM
说服许多Windows应用程序认为文件是UTF-8,但也检查编译器是否有源编码选项。请注意使用wcout
和宽字符串(L"..."
)。此外,_setmode
用于更改stdout以支持UTF-16输出。
#include <iostream>
#include <io.h>
#include <fcntl.h>
using namespace std;
void win(){
wcout << L"░░░░█▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█" << endl;
wcout << L"░░░░█▒▒▄▀▀▀▀▀▄▄▒▒▒▒▒▒▒▒▒▄▄▀▀▀▀▀▀▄" << endl;
wcout << L"░░▄▀▒▒▒▄█████▄▒█▒▒▒▒▒▒▒█▒▄█████▄▒█" << endl;
wcout << L"░█▒▒▒▒▐██▄████▌▒█▒▒▒▒▒█▒▐██▄████▌▒█" << endl;
wcout << L"▀▒▒▒▒▒▒▀█████▀▒▒█▒░▄▒▄█▒▒▀█████▀▒▒▒█" << endl;
wcout << L"▒▒▐▒▒▒░░░░▒▒▒▒▒█▒░▒▒▀▒▒█▒▒▒▒▒▒▒▒▒▒▒▒█" << endl;
wcout << L"▒▌▒▒▒░░░▒▒▒▒▒▄▀▒░▒▄█▄█▄▒▀▄▒▒▒▒▒▒▒▒▒▒▒▌" << endl;
wcout << L"▒▌▒▒▒▒░▒▒▒▒▒▒▀▄▒▒█▌▌▌▌▌█▄▀▒▒▒▒▒▒▒▒▒▒▒▐" << endl;
wcout << L"▒▐▒▒▒▒▒▒▒▒▒▒▒▒▒▌▒▒▀███▀▒▌▒▒▒▒▒▒▒▒▒▒▒▒▌" << endl;
wcout << L"▀▀▄▒▒▒▒▒▒▒▒▒▒▒▌▒▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▒▒█" << endl;
wcout << L"▀▄▒▀▄▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▄▄▄▄▒▒▒▒▒▒▄▄▀" << endl;
wcout << L"▒▒▀▄▒▀▄▀▀▀▄▀▀▀▀▄▄▄▄▄▄▄▀░░░░▀▀▀▀▀▀" << endl;
}
int main(){
_setmode(_fileno(stdout), _O_U16TEXT);
win();
return 0;
}
输出:
答案 1 :(得分:1)
您使用的是Windows还是基于unix的系统(macos / linux),因为Windows默认情况下不使用utf8,如macos和linux。
在macos(我正在使用)上,你的代码编译运行完全正常:
#include <iostream>
using namespace std;
void win(){
cout << "░░░░█▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█" << endl;
cout << "░░░░█▒▒▄▀▀▀▀▀▄▄▒▒▒▒▒▒▒▒▒▄▄▀▀▀▀▀▀▄" << endl;
cout << "░░▄▀▒▒▒▄█████▄▒█▒▒▒▒▒▒▒█▒▄█████▄▒█" << endl;
cout << "░█▒▒▒▒▐██▄████▌▒█▒▒▒▒▒█▒▐██▄████▌▒█" << endl;
cout << "▀▒▒▒▒▒▒▀█████▀▒▒█▒░▄▒▄█▒▒▀█████▀▒▒▒█" << endl;
cout << "▒▒▐▒▒▒░░░░▒▒▒▒▒█▒░▒▒▀▒▒█▒▒▒▒▒▒▒▒▒▒▒▒█" << endl;
cout << "▒▌▒▒▒░░░▒▒▒▒▒▄▀▒░▒▄█▄█▄▒▀▄▒▒▒▒▒▒▒▒▒▒▒▌" << endl;
cout << "▒▌▒▒▒▒░▒▒▒▒▒▒▀▄▒▒█▌▌▌▌▌█▄▀▒▒▒▒▒▒▒▒▒▒▒▐" << endl;
cout << "▒▐▒▒▒▒▒▒▒▒▒▒▒▒▒▌▒▒▀███▀▒▌▒▒▒▒▒▒▒▒▒▒▒▒▌" << endl;
cout << "▀▀▄▒▒▒▒▒▒▒▒▒▒▒▌▒▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▒▒█" << endl;
cout << "▀▄▒▀▄▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▄▄▄▄▒▒▒▒▒▒▄▄▀" << endl;
cout << "▒▒▀▄▒▀▄▀▀▀▄▀▀▀▀▄▄▄▄▄▄▄▀░░░░▀▀▀▀▀▀" << endl;
}
int main(){
win();
return 0;
}
并给出所需的输出:
░░░░█▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
░░░░█▒▒▄▀▀▀▀▀▄▄▒▒▒▒▒▒▒▒▒▄▄▀▀▀▀▀▀▄
░░▄▀▒▒▒▄█████▄▒█▒▒▒▒▒▒▒█▒▄█████▄▒█
░█▒▒▒▒▐██▄████▌▒█▒▒▒▒▒█▒▐██▄████▌▒█
▀▒▒▒▒▒▒▀█████▀▒▒█▒░▄▒▄█▒▒▀█████▀▒▒▒█
▒▒▐▒▒▒░░░░▒▒▒▒▒█▒░▒▒▀▒▒█▒▒▒▒▒▒▒▒▒▒▒▒█
▒▌▒▒▒░░░▒▒▒▒▒▄▀▒░▒▄█▄█▄▒▀▄▒▒▒▒▒▒▒▒▒▒▒▌
▒▌▒▒▒▒░▒▒▒▒▒▒▀▄▒▒█▌▌▌▌▌█▄▀▒▒▒▒▒▒▒▒▒▒▒▐
▒▐▒▒▒▒▒▒▒▒▒▒▒▒▒▌▒▒▀███▀▒▌▒▒▒▒▒▒▒▒▒▒▒▒▌
▀▀▄▒▒▒▒▒▒▒▒▒▒▒▌▒▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▒▒█
▀▄▒▀▄▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▄▄▄▄▒▒▒▒▒▒▄▄▀
▒▒▀▄▒▀▄▀▀▀▄▀▀▀▀▄▄▄▄▄▄▄▀░░░░▀▀▀▀▀▀
但在Windows上打印:
????????????????????????????
???????????????????????????????
??????????????????????????????????
????????????????????????????????????
等等。
所以我认为问题在于您使用的机器/终端不支持unicode。 一个解决方案可能是使用std :: wcout,这对于&#34;宽&#34;一个例子可能是这样的:
std::wcout << L"█" << std::endl;
或使用utf16:
#include <iostream>
using std::cout;
using std::endl;
void win(){
cout << "\u2591\u2591\u2591\u2591\u2588\u2592\u2592\u2592\u2592\u2591\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2588" << endl;
cout << "\u2591\u2591\u2591\u2591\u2588\u2592\u2592\u2584\u2580\u2580\u2580\u2580\u2580\u2584\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2584\u2584\u2580\u2580\u2580\u2580\u2580\u2580\u2584" << endl;
cout << "\u2591\u2591\u2584\u2580\u2592\u2592\u2592\u2584\u2588\u2588\u2588\u2588\u2588\u2584\u2592\u2588\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2588\u2592\u2584\u2588\u2588\u2588\u2588\u2588\u2584\u2592\u2588" << endl;
cout << "\u2591\u2588\u2592\u2592\u2592\u2592\u2590\u2588\u2588\u2584\u2588\u2588\u2588\u2588\u258C\u2592\u2588\u2592\u2592\u2592\u2592\u2592\u2588\u2592\u2590\u2588\u2588\u2584\u2588\u2588\u2588\u2588\u258C\u2592\u2588" << endl;
cout << "\u2580\u2592\u2592\u2592\u2592\u2592\u2592\u2580\u2588\u2588\u2588\u2588\u2588\u2580\u2592\u2592\u2588\u2592\u2591\u2584\u2592\u2584\u2588\u2592\u2592\u2580\u2588\u2588\u2588\u2588\u2588\u2580\u2592\u2592\u2592\u2588" << endl;
cout << "\u2592\u2592\u2590\u2592\u2592\u2592\u2591\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2588\u2592\u2591\u2592\u2592\u2580\u2592\u2592\u2588\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2588" << endl;
cout << "\u2592\u258C\u2592\u2592\u2592\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2584\u2580\u2592\u2591\u2592\u2584\u2588\u2584\u2588\u2584\u2592\u2580\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u258C" << endl;
cout << "\u2592\u258C\u2592\u2592\u2592\u2592\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2580\u2584\u2592\u2592\u2588\u258C\u258C\u258C\u258C\u258C\u2588\u2584\u2580\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2590" << endl;
cout << "\u2592\u2590\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u258C\u2592\u2592\u2580\u2588\u2588\u2588\u2580\u2592\u258C\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u258C" << endl;
cout << "\u2580\u2580\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u258C\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2590\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2588" << endl;
cout << "\u2580\u2584\u2592\u2580\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2590\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2584\u2584\u2584\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2584\u2584\u2580" << endl;
cout << "\u2592\u2592\u2580\u2584\u2592\u2580\u2584\u2580\u2580\u2580\u2584\u2580\u2580\u2580\u2580\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2580\u2591\u2591\u2591\u2591\u2580\u2580\u2580\u2580\u2580\u2580" << endl;
}
int main(){
win();
}
但是,如果您的终端不支持Unicode,则无法打印它。