0

Hi, I have a std::string getName(){return name} function and std::string name is a private variable. The problem is that when ever I try to getName() == object , the statement is always false even when the values are the same.

    if (command.compare(0, 4, "get ") == 0){
        std::string object = command.substr(4);
        for (std::vector<Item>::size_type i = 0; i < vec_Items.size(); i++){
            if (vec_Items[i].getName() == object){
                std::cout << vec_Items[i].getName();
                std::cout << "You picked up the [" << object << "].";
                player.AddItem(vec_Items[i]);
                vec_Items.erase(vec_Items.begin() + i);
                return;
            }
        }
        std::cout << "What [" << object << "]?";
        return;
    }

Edit: Solved it. The getName is not equal to object. renamed the Item.

Edited by HuePig

2
Contributors
1
Reply
31
Views
3 Years
Discussion Span
Last Post by Search_not
0

*Ignore this post please

Edited by Search_not: Sorry, only saw after I posted that you have already solved the problem. Mark your article as solved if you no longer require assistance

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.