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'

Recommended Answers

"=" != "=="

Jump to Post

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).

Jump to Post

All 5 Replies

"=" != "=="

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).

stack.top()= word

should be

stack.top()==word

= is used for assignment

stack.top()= word

should be

stack.top()==word

= is used for assignment

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

oh, I didn't notice that we posted at the same time. haha

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.