C++ 是什么导致字符串输出中出现笑脸?

C++ 是什么导致字符串输出中出现笑脸?,c++,C++,这个程序基本上将中缀转换为后缀。问题是,-和/变成了这样的笑脸:) 问题是,它显示不同的字符,而不是预期的减号或除号 // the program is used to convert a infix expression to a postfix expression #include<iostream> #include<stdio.h> #include<conio.h> #include<string.h> #include<s

这个程序基本上将中缀转换为后缀。问题是,
-
/
变成了这样的笑脸:)

问题是,它显示不同的字符,而不是预期的减号或除号

// the program is used to convert a infix expression to a postfix expression



#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<string>

using namespace std;


const int size =50;
char infix[size],postfix[size],stack[size];
int top=-1;

int precedence(char ch);   // function to get the precedence of the operator
char pop();  //function to pop an element from the stack
char topelement();  // returns the top element of the stack
void push(char ch);  // pushes an element into the stack



int main()
{
     char ele,elem,st[2];
     int prep,pre,popped,j=0,chk=0;
     char strr[50];
     cout<<"Enter infix notation : "<<endl;
     cin>>infix;
     strcpy(postfix," ");

     //gets(infix);

     for(int i=0;infix[i]!=0;i++)
          {
                  if(infix[i]!='('&&infix[i]!=')'&&infix[i]!='^'&&infix[i]!='*'&&infix[i]!='/'&&infix[i]!='+'&&infix[i]!='-')     
                       postfix[j++]=infix[i];
                  else if(infix[i]=='(')
                      {
                         elem=infix[i];
                         push(elem);
                      }
                  else if(infix[i]==')')
                      {
                         while(popped=pop() != '(')
                             postfix[j++]=popped;
                      }
                  else
                      {
                         elem=infix[i];
                         pre=precedence(elem);//stores the precedence of operator coming frm infix
                         ele=topelement();
                         prep=precedence(ele);//stores the precedence of operator at the top of the stack

                         if(pre > prep)
                           push(elem);                                         

                         else
                           {
                                while(prep >= pre)
                                  {
                                     if(ele=='#')
                                       break;
                                     popped=pop();
                                     ele=topelement();
                                     postfix[j++]=popped;
                                     prep=precedence(ele);
                                   }
                                   push(elem);
                            }
                         }
             } 

          while((popped=pop())!='#')
              postfix[j++]=popped;
          postfix[j]='\0';

          cout<<"\n post fix :"<<postfix<<endl;

           system("pause");
           return 0;
}

int precedence(char ch)
{
       switch(ch)
          {
               case '^' : return 5;
               case '/' : return 4;
               case '*' : return 4;                                            
               case '+' : return 3;
               case '-' : return 3;
               default  : return 0;
          }
}

char pop()                  //function to pop the element from the stack
{
     char ret;
     if(top!=-1)
       {  ret =stack[top];
          top--;
          return ret;
       }
     else
        return '#';
}

char topelement()          // function to return top element from the stack without popping
{     
      char ch;
      if(top!=-1)
        ch=stack[top];
      else
         ch='#';
       return ch;
}

void push(char ch)          // function to push an element in the stack
{
     if(top!=size-1)
         {
            top++;
            stack[top]= ch;
         }
}         
//该程序用于将中缀表达式转换为后缀表达式
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
常数int size=50;
字符中缀[size],后缀[size],堆栈[size];
int top=-1;
int优先级(字符ch);//函数以获取运算符的优先级
char-pop()//函数从堆栈中弹出一个元素
char topelement();//返回堆栈的顶部元素
无效推送(char ch);//将元素推入堆栈
int main()
{
charele,elem,st[2];
int prep,pre,popped,j=0,chk=0;
char-strr[50];
cout=pre)
{
如果(ele='#')
打破
popped=pop();
ele=topelement();
后缀[j++]=弹出;
prep=优先级(ele);
}
推(elem);
}
}
} 
而((popped=pop())!='#')
后缀[j++]=弹出;
后缀[j]='\0';

cout您正在打印
\x01
字符(而不是预期的
-
/
)<代码>☺是它的显示方式。

您正在打印
\x01
字符(而不是预期的
-
/
)<代码>☺是如何显示它的