2017-10-06 66 views
-1

我想创建一个函数,看看'-'标志,并检查是否是一个减号或负号的基础上,如果它有一个' '(空间)在它的前面。我通过比较我现有的字符(infix[x])和infix[x+1];我不断收到错误,但我不确定它是否因为没有正确传递或其他内容?错误传递字符串和字符布尔功能

 for(unsigned x = 0; x < infix.length(); ++x) 
     { 
      // place numbers (standard, decimal, & negative) 
      // numbers onto the 'postfix' string 
      if((isdigit(infix[x])) || (infix[x] == '.')) 
      { 
       postfix += infix[x]; 
      } 
      else if ((infix[x] == '-')) 
      { 
        if(checkfornegative(infix[x], infix)== 1)) // error: expected primary-expression before ‘)’ token 
      if(checkfornegative(infix[x], infix)== 1)) 
      { 
         postfix+= " "; 
      } 
      else if(checkfornegative(infix[x], infix)== 0)) //error: expected primary-expression before ‘)’ token 
       if(checkfornegative(infix[x], infix)== 1)) 

       { 
        postfix += infix[x]; 
       } 

      } 

// This is the function in using 
bool checkfornegative(char C, string& QQ) 
{ 
     bool status; 
     if((C == '-') && (QQ[C+1] == ' ')) 
     { 
       status = true; 
     } 
     else if((C == '-') && (QQ[C+1] != ' ')) 
     { 
       status = false; 
    } 
    return status; 
} 
+0

根据一个最小的完整示例在这里有一些背景会有很大的帮助。这些函数是如何被调用的?你提供什么数据? – tadman

+1

你的括号不平衡,这不能是你正在运行的代码。 – Barmar

+0

'QQ [C + 1]'没有意义。 'C'是一个字符,不是字符串中的索引。 – Barmar

回答

2

你得到的编译错误,因为你必须在if条件下额外的右括号。

if(checkfornegative(infix[x], infix)== 1)) // error: expected primary-expression before ‘)’ token 

从条件中删除最后一个右括号。第二种情况也是如此。

但是,在您的代码中有几个问题,但它们不是编译错误。

+0

解决了它,无法看到它为我的生活。非常感谢。 – G3Spin