-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;
}
根据一个最小的完整示例在这里有一些背景会有很大的帮助。这些函数是如何被调用的?你提供什么数据? – tadman
你的括号不平衡,这不能是你正在运行的代码。 – Barmar
'QQ [C + 1]'没有意义。 'C'是一个字符,不是字符串中的索引。 – Barmar