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 << "].";
                vec_Items.erase(vec_Items.begin() + i);
        std::cout << "What [" << object << "]?";

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

Member Avatar

*Ignore this post please

Be a part of the DaniWeb community

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