简体   繁体   中英

How to make special characters?

I want the console to display the character '♞'.

I use:

wchar_t tab2[8][8];

tab2[x1][x2]=L'♞';

For example, but for this character, the console displays "9822".

My code (I post just the main code, the rest is irrelevant for this problem).

#include <iostream>
#include <string>
#include <vector>
#include <cwchar>
#include "fonctions.hpp"

using namespace std;

int main()
{
    bool tab1[8][8];
    wchar_t tab2[8][8];
    for(int i=0;i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            tab1[i][j]=false;
            tab2[i][j]=L' ';
        //  fgets(tab2[i][j], 1, stdin);

        }
    }

    int b=0, c=0;
    cout<<"Veuillez entrer les coordonnées de la case de départ souhaitée!"<<endl;
    do
    {
        cout<<"Abscisse: ";
        cin>>b;
    }while((b<1)||(b>8));
    do
    {
        cout<<"Ordonnée: ";
        cin>>c;
    }while((c<1)||(c>8));

    tab1[b-1][c-1]=true;
    tab2[b-1][c-1]=9822;

  int q1=b-1;
    int q2=c-1;
    vector<Point> v=Combinations(q1,q2,tab1);
    int continuation=0;

    while(!v.empty()&&(continuation==0))
    {

        Point p1=TheRightPoint(v,tab1);

        int x1=p1.GetX();
        int x2=p1.GetY();

        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][0]<<"+"<<tab2[1][0]<<"+"<<tab2[2][0]<<"+"<<tab2[3][0]<<"+"<<tab2[4][0]<<"+"<<tab2[5][0]<<"+"<<tab2[6][0]<<"+"<<tab2[7][0]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][1]<<"+"<<tab2[1][1]<<"+"<<tab2[2][1]<<"+"<<tab2[3][1]<<"+"<<tab2[4][1]<<"+"<<tab2[5][1]<<"+"<<tab2[6][1]<<"+"<<tab2[7][1]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][2]<<"+"<<tab2[1][2]<<"+"<<tab2[2][2]<<"+"<<tab2[3][2]<<"+"<<tab2[4][2]<<"+"<<tab2[5][2]<<"+"<<tab2[6][2]<<"+"<<tab2[7][2]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][3]<<"+"<<tab2[1][3]<<"+"<<tab2[2][3]<<"+"<<tab2[3][3]<<"+"<<tab2[4][3]<<"+"<<tab2[5][3]<<"+"<<tab2[6][3]<<"+"<<tab2[7][3]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][4]<<"+"<<tab2[1][4]<<"+"<<tab2[2][4]<<"+"<<tab2[3][4]<<"+"<<tab2[4][4]<<"+"<<tab2[5][4]<<"+"<<tab2[6][4]<<"+"<<tab2[7][4]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][5]<<"+"<<tab2[1][5]<<"+"<<tab2[2][5]<<"+"<<tab2[3][5]<<"+"<<tab2[4][5]<<"+"<<tab2[5][5]<<"+"<<tab2[6][5]<<"+"<<tab2[7][5]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][6]<<"+"<<tab2[1][6]<<"+"<<tab2[2][6]<<"+"<<tab2[3][6]<<"+"<<tab2[4][6]<<"+"<<tab2[5][6]<<"+"<<tab2[6][6]<<"+"<<tab2[7][6]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;
        cout<<"+"<<tab2[0][7]<<"+"<<tab2[1][7]<<"+"<<tab2[2][7]<<"+"<<tab2[3][7]<<"+"<<tab2[4][7]<<"+"<<tab2[5][7]<<"+"<<tab2[6][7]<<"+"<<tab2[7][7]<<"+"<<endl;
        cout<<"+-+-+-+-+-+-+-+-+"<<endl;

        tab1[x1][x2]=true;
        tab2[x1][x2]=L'♞';
        //fgets(tab2[x1][x2], 1, stdin);


        cout<<"Taper un autre chiffre que 0 pour arrêter!"<<endl;
        cin>>continuation;
        v=Combinations(x1,x2,tab1);

    }

    return 0;


}

What the console displays:

> +-+-+-+-+-+-+-+-+
+32+32+32+32+32+32+32+32+
+-+-+-+-+-+-+-+-+
+32+32+9822+32+32+32+32+32+
+-+-+-+-+-+-+-+-+
+32+32+32+32+32+32+32+32+
+-+-+-+-+-+-+-+-+
+32+32+32+9822+32+32+32+32+
+-+-+-+-+-+-+-+-+
+32+32+32+32+32+32+32+32+
+-+-+-+-+-+-+-+-+
+32+32+32+32+32+32+32+32+
+-+-+-+-+-+-+-+-+
+32+32+32+32+32+32+32+32+
+-+-+-+-+-+-+-+-+
+32+32+32+32+32+32+32+32+
+-+-+-+-+-+-+-+-+

对于wchar_t字符串,请使用std::wcout代替std::cout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM