0

no idea what to do about this error =/

#include <stack>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

int main ()
{
        stack<string> stack;
        ifstream inFile;
        string consoleStr = "Enter Filename>> ";
        string fileName;
        string word = "";
        char c;

        cout << "Welcome! Enter filename or quit to exit.\n" << endl;
        cout << consoleStr;
        cin >> fileName;
        while(fileName.compare("quit") != 0) {
                cout << "Opening file:\n\n";
                inFile.open(fileName.c_str());

                if(inFile.is_open()) {
                        while(!inFile.eof()) {

                                c = inFile.get();

                                if(c = 40 ) {
                                        word.append(1,c);
                                        stack.push(word);

                                }






                                else if(c = 41) {

                                        if(stack.top()= word) {

                                                stack.pop();
                                        }
                                        if(stack.top() != word) {
                                                cout << " Unmatched () " <<endl;
                                        }
                                        word = "";


                                }



                        }
                        stack.push(word);
                        word = "";
                }
                else {
                        cout << "Could not open file!\n";
                }

                inFile.close();
                inFile.clear();

                while(stack.size() != 0) {
                        stack.pop();
                }

                cout << consoleStr;
                cin >> fileName;
        }
        return 0;
}

matching.cpp: In function `int main()':
matching.cpp:42: error: could not convert `(+(&stack)->std::stack<_Tp, _Sequence>::top [with _Tp = std::string, _Sequence = std::deque<std::string, std::allocator<std::string> >]())->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(&word))))' to `bool'

3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by prushik
0

You might want to check the rest of your code for the same mistake. It's an easy one to make and sometimes will compile but not behave the way you would like (like another part of your code).

0

stack.top()= word

should be

stack.top()==word

= is used for assignment

I prefer my way of saying it, but same thing.:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.