CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2012
    Posts
    68

    error: no match for ' ' problem

    so there is something wrong with the compatibility of my expression variable with everything im trying to use it for. Do I need to create an alias for it to use it the way im am attempting to use it? or reference it as something else?

    the build messages are saying "error: no match for operator!= in 'expression.std::vector<_TP, _Alloc>...ect

    I am making a program to convert a give integer expression that is in regular notation and converting it to post fix

    Code:
    int arithmetic_expression::inputInfix(std::string inputString)
    {
    
        std::vector<std::string> expression = parse_string(inputString);
        stack<int> intStack;
        int output[100];
        int n = 0;
        int n1;
        int *o;
    
        o = &output[0];
    
        while(expression[n] != 0){
    
        if(isdigit(expression[n])  || isalpha(expression[n])){
           *o = expression[n];
           n++;
           o++;
        }
        if(expression[n] == '('){
           intStack.push(expression[n]);
           n++
        }
        if(expression[n] == ')'){
            n1 = intStack.top();
            intStack.pop();
            while(n1 != '('){
              *o = n1;
              o++;
              n1 = intStack.top();
              intStack.pop();
            }
            n++
        }
    
         if(expression[n] == '+' || expression[n] == '-' || expression[n] == '*' || expression[n] == '/' || expression[n] == '&#37;'){
            if(intStack.empty() == true){
               intStack.push(expression[n]);
               }else{
                 n1 = intStack.top();
                 intStack.pop();
                 while(priority(n1) >= priority(expression[n]){
                    *o = n1;
                    o++;
                    n1 = intStack.top();
                    intStack.pop();
                    }
                    intStack.push(n1);
                    intStack.push(expression[n]);
    
               }
               n++
         }
         while(!intStack.empty()){
            *o = intStack.top();
            o++
            intStack.pop()
        }
        *o = '\0';
    
        int valid = createExpressionTree(expression);
        if (!valid) {
            topPtr = NULL;
        }
    
        return(valid);
    
    }

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: error: no match for ' ' problem

    Code:
        while(expression[n] != 0){
    expression[n] is a string
    use
    Code:
        while(!expression[n].empty()){
    kurt

    EDIT: i see you seem to think it's a char. There are more errors like this like

    Code:
        if(isdigit(expression[n])  || isalpha(expression[n])){
    Last edited by ZuK; April 23rd, 2012 at 07:18 PM.

  3. #3
    Join Date
    Feb 2012
    Posts
    68

    Re: error: no match for ' ' problem

    how would I go about formatting the isdigit and isalpha line to make it a string instead?

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: error: no match for ' ' problem

    Quote Originally Posted by chucker View Post
    how would I go about formatting the isdigit and isalpha line to make it a string instead?
    isdigit is a function that tests a single character to see if it is a digit. Similarly, the isalpha tests a single character to see if it is an alphabetic character.

    So there is no way to "format" these functions to do something they are not written to do. You have to write your own routine to test if an entire string is whatever you feel it should be.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Feb 2012
    Posts
    68

    Re: error: no match for ' ' problem

    that sounds reasonable. But generally how do I go about formatting my expression[n] variable to be recognized as a string? Like when it is not empty

  6. #6
    Join Date
    Feb 2012
    Posts
    68

    Re: error: no match for ' ' problem

    like at the line where it says:

    Code:
     if(expression[n] == '('){
    should it be expression[n].parse_string()?

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Post Re: error: no match for ' ' problem

    Quote Originally Posted by chucker View Post
    that sounds reasonable. But generally how do I go about formatting my expression[n] variable to be recognized as a string? Like when it is not empty
    You have a vector of string. The name of the vector is expression. Each element in that vector is an entire string. So expression[0] is a string, expression[1] is a string, expression[2] is a string.

    Well, given a string how do you access a character? You use operator [] on that string. I believe you erroneously used operator [] to access each string in the vector. You need to go one more level to access the actual characters of the string:
    Code:
    (expression[0]) [0] --> the first character in string 0
    (expression[0]) [1] --> the second character in string 0
    
    (expression[1]) [0] --> the first character in string 1
    (expression[1]) [1] --> the second character in string 1
    
    etc...
    You can remove the parentheses -- I added them so that you can understand what is being done to access each character.

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Feb 2012
    Posts
    68

    Re: error: no match for ' ' problem

    I didnt get any compile errors but Im not sure how to test it without putting it into a tree expression tree yet. Did I implement it the way you meant?



    Code:
    int arithmetic_expression::inputInfix(std::string inputString)
    {
    
        std::vector<std::string> expression = parse_string(inputString);
    
      stack<string> charStack;
    
        int n = 0;
    
    
    
    
    
    
       while(!expression[n].empty()){
    
    
        if(expression[n][0] == '('){
           charStack.push(expression[n]);
           n++;
        }
        if(expression[n][0] == ')'){
            expression[n] = charStack.top();
            charStack.pop();
            while(expression[n][0] != '('){
    
    
               expression[n] = charStack.top();
              charStack.pop();
            }
            n++;
        }
    
         if(expression[n][0] == '+' || expression[n][0] == '-' || expression[n][0] == '*' || expression[n][0] == '/'){
            if(charStack.empty() == true){
               charStack.push(expression[n]);
               }else{
                 expression[n] = charStack.top();
                 charStack.pop();
    
               }
               n++;
         }

  9. #9
    Join Date
    Feb 2012
    Posts
    68

    Re: error: no match for ' ' problem

    okay here is the real code actually, and i did try and test if the conversion to RPN would print out okay. but for example one of the inputs is "31+25*2"; and all that my code could spit out is "31"

    Code:
    int arithmetic_expression::inputInfix(std::string inputString)
    {
    
        std::vector<std::string> expression = parse_string(inputString);
    
      stack<string> charStack;
    
        int n = 0;
    
    
    
    
    
    
       while(!expression[n].empty()){
    
    
        if(expression[n][0] == '('){
           charStack.push(expression[n]);
           n++;
        }
        if(expression[n][0] == ')'){
            expression[n] = charStack.top();
            charStack.pop();
            while(expression[n][0] != '('){
    
    
               expression[n] = charStack.top();
              charStack.pop();
            }
            n++;
        }
    
         if(expression[n][0] == '+' || expression[n][0] == '-' || expression[n][0] == '*' || expression[n][0] == '/'){
            if(charStack.empty() == true){
               charStack.push(expression[n]);
               }else{
                 expression[n] = charStack.top();
                 charStack.pop();
    
               }
               n++;
         }
    cout << "after" << endl;
    cout << expression[n];
    
        int valid = createExpressionTree(expression);
        if (!valid) {
            topPtr = NULL;
    
    
        return(valid);
    
    }}}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured