簡體   English   中英

我如何在C ++中輸出這些符號

[英]How can I output these symbols in c++

我要輸出這張臉,我看到的只是問號符號

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;
    }

如果您使用的是Windows,則以下代碼將一直有效:

  • 控制台字體支持字符。 我正在使用Consolas字體。
  • 源代碼是從以支持字符的編碼保存的源代碼編譯而來的。 另存為UTF-8 w/ BOM UTF-8,這使許多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;
}

輸出:

控制台截圖

您使用的是Windows還是基於Unix的系統(macos / linux),因為默認情況下Windows不像macos和linux一樣使用utf8。

在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用於“寬”字符,例如:

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,則無法打印。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM